键盘记录功能 [英] Keyboard logging functionality

查看:82
本文介绍了键盘记录功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个启动Internet Explorer的程序,然后计算

多少< ENTER>在IE中按下键。我已经看到很多

引用了SetWindowsHookEx()API调用,但我找到的所有来源

似乎都是零碎的,不完整的。我正在使用VC ++ .NET,并且如果可能的话,宁可避免使用WinAPI。是否有更简单的方法

(可能使用.NET)来执行此操作?

I need to write a program that launches Internet Explorer, then counts
how many <ENTER> keys are pressed inside IE. I''ve seen a lot of
references to the SetWindowsHookEx() API call, but all sources I found
seem to be piece-meal and incomplete. I''m using VC++ .NET, and would
rather avoid using the WinAPI, if possible. Is there an easier way
(perhaps using .NET) to do this?

推荐答案

" Stephen Corey" < swc@_NOSPAM_wardandsmith.com>在消息中写道

news:u1 ************** @ TK2MSFTNGP12.phx.gbl ...
"Stephen Corey" <swc@_NOSPAM_wardandsmith.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
我看到我可以使用WH_KEYBOARD_LL创建一个没有单独的DLL的全局钩子,但我无法在任何地方找到任何示例。


嗯,文档在哪里说的?在SetWindowsHookEx()

的帮助条目中,它们是一个表,其中WH_KEYBOARD_LL挂钩被列为仅具有

全局范围。


然后在调用中的HOOKPROC参数的备注中有这个


< quote>

[in]指向钩子程序的指针。如果dwThreadId参数为零或

指定由不同进程创建的线程的标识符,则

lpfn参数必须指向动态链接库中的挂钩过程

(DLL)。否则,lpfn可以指向与当前进程关联的代码中的钩子程序



< / quote>


一起使用意味着需要一个DLL,不是吗?

适用于VB或C#。你们两个都知道吗?我甚至会使用带有的DLL例如,如果找不到更好的东西......
I see that I can use WH_KEYBOARD_LL to create a global hook WITHOUT having
a separate DLL, but I can''t find any examples anywhere.
Hmm, where do the docs say that? In the help entry for SetWindowsHookEx()
their is a table in which the WH_KEYBOARD_LL hook is listed as having only
global scope.

Then in the remarks for the HOOKPROC parameter in the call there is this

<quote>
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or
specifies the identifier of a thread created by a different process, the
lpfn parameter must point to a hook procedure in a dynamic-link library
(DLL). Otherwise, lpfn can point to a hook procedure in the code associated
with the current process.
</quote>

Taken together that means that a DLL is required, no?
is for VB or C#. Do either of you know of any?? I''d even take a "with the
DLL" example if nothing better can be found...




平台中Hook.c文件中的全局挂钩有旧的C代码

SDK'的目录


Samples\multimedia\gdi \ WinCap32


注意它的使用是规范的钩子检测到条件

但是没有处理它。它会向应用程序发回一条消息,即
种植钩子,该应用程序是处理它的应用程序。这是正确的方式

因为


a)全球钩子应该有小的足迹,因为它们膨胀_every_ windowed

应用程序

b)他们的代码在被挂钩的应用程序的上下文中运行。一个错误的

挂钩可能会导致一个优秀的应用程序崩溃


问候,




There is old C code for a global hook in the file Hook.c in the Platform
SDK''s directory

Samples\multimedia\gdi\WinCap32

Note its use of the hook is canonical in that the hook detects a condition
but does NOT handle it. It posts a message back to the application which
planted the hook and that application is the one that handles it. This is
the right way because

a) Global hooks should have small footprints as they bloat _every_ windowed
application
b) Their code runs in the context of the application being hooked. An errant
hook can crash an otherwise fine application

Regards,
Will


William DePalo [MVP VC ++]写道:
William DePalo [MVP VC++] wrote:
" Stephen Corey" < swc@_NOSPAM_wardandsmith.com>在消息中写道
新闻:u1 ************** @ TK2MSFTNGP12.phx.gbl ...
"Stephen Corey" <swc@_NOSPAM_wardandsmith.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
我看到我可以使用WH_KEYBOARD_LL来创建一个没有单独DLL的全局钩子,但我无法在任何地方找到任何示例。
I see that I can use WH_KEYBOARD_LL to create a global hook WITHOUT having
a separate DLL, but I can''t find any examples anywhere.



嗯,文档在哪里说的?在SetWindowsHookEx()的帮助条目中,它们是一个表,其中WH_KEYBOARD_LL挂钩被列为仅具有全局范围。

然后在HOOKPROC参数的备注中这个电话有这个

< quote>
[in]指向钩子程序的指针。如果dwThreadId参数为零或
指定由不同进程创建的线程的标识符,则
lpfn参数必须指向动态链接库中的挂钩过程
(DLL)。否则,lpfn可以指向与当前进程关联的代码中的钩子过程。
< / quote>

这意味着需要一个DLL,没有?


Hmm, where do the docs say that? In the help entry for SetWindowsHookEx()
their is a table in which the WH_KEYBOARD_LL hook is listed as having only
global scope.

Then in the remarks for the HOOKPROC parameter in the call there is this

<quote>
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or
specifies the identifier of a thread created by a different process, the
lpfn parameter must point to a hook procedure in a dynamic-link library
(DLL). Otherwise, lpfn can point to a hook procedure in the code associated
with the current process.
</quote>

Taken together that means that a DLL is required, no?

适用于VB或C#。你们两个都知道吗?我甚至会使用带有的DLL例如,如果没有更好的东西可以找到...
is for VB or C#. Do either of you know of any?? I''d even take a "with the
DLL" example if nothing better can be found...



平台中的Hook.c文件中的全局挂钩有旧的C代码
SDK的目录<示例\ manymedia \ gdi \ WinCap32

请注意,钩子的使用是规范的,因为钩子检测到一个条件但不处理它。它会将消息发回给应用程序,该应用程序将挂起该应用程序并且该应用程序是处理它的应用程序。这是正确的方法,因为

a)全局钩子应该有小脚印,因为它们膨胀_every_ windowed
应用程序
b)它们的代码运行在应用程序被钩住了。一个错误的挂钩可能会导致其他优质应用程序崩溃

问候,


There is old C code for a global hook in the file Hook.c in the Platform
SDK''s directory

Samples\multimedia\gdi\WinCap32

Note its use of the hook is canonical in that the hook detects a condition
but does NOT handle it. It posts a message back to the application which
planted the hook and that application is the one that handles it. This is
the right way because

a) Global hooks should have small footprints as they bloat _every_ windowed
application
b) Their code runs in the context of the application being hooked. An errant
hook can crash an otherwise fine application

Regards,
Will




专家交换,以及一些其他网站,人们提到

与该钩子,你没有必要将你的代码放在一个单独的DLL中。


所以,要管理的主要代码,我想DLL代码需要是

unmanaged ?? DLL是一个什么类型的项目?


是否没有专为VC ++ .NET设计的代码?



In experts exchange, as well as a few other sites, people mentioned that
with that hook, you didn''t have to have your code in a separate DLL.

So, the main code to be managed, and I guess the DLL code needs to be
unmanaged?? What type of a project is the DLL?

Is there no code that is designed for VC++ .NET?


"斯蒂芬科里 < swc@_NOSPAM_wardandsmith.com>在消息中写道

新闻:OA ************* @ TK2MSFTNGP14.phx.gbl ...
"Stephen Corey" <swc@_NOSPAM_wardandsmith.com> wrote in message
news:OA*************@TK2MSFTNGP14.phx.gbl...
William DePalo [MVP VC ++]写道:
在专家交流,以及一些其他网站,人们提到,使用该钩子,你没有必要在单独的DLL中的代码。


嗯。挂钩除了调用SetWindowsHookEx()

之外的进程。听起来很震撼。

所以,要管理的主要代码,我猜DLL代码需要不受管理? DLL的项目类型是什么?


DLL将是原生的。如果您使用的是VS.Net 2003,首先选择C ++

项目,然后单击Win32图标。然后单击应用程序设置

并选择DLL选项。 A

是否没有为VC ++ .NET设计的代码?
William DePalo [MVP VC++] wrote:
In experts exchange, as well as a few other sites, people mentioned that
with that hook, you didn''t have to have your code in a separate DLL.
Hmm. To hook a process other than the one in which the SetWindowsHookEx()
call is made. Sounds hokey to me.
So, the main code to be managed, and I guess the DLL code needs to be
unmanaged?? What type of a project is the DLL?
The DLL would be native. If you are using VS.Net 2003 you first select C++
projects and then click on the Win32 icon. Then click Application Settings
and choose the DLL option. A
Is there no code that is designed for VC++ .NET?




据我所知,没有。意识到我不是自称是.Net专家。


问候,





As far as I know, no. Realize that I don''t claim to be a .Net expert.

Regards,
Will


这篇关于键盘记录功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆