处理所有键盘输入(挂钩)
我正在制作一个程序来记录所有键盘操作,并将这些信息存储到日志文件(键盘记录器)中。我似乎找不到一个好的方法来做到这一点。
到目前为止我所拥有的: LowLevelKeyboardProc,虚拟按键代码+被按下的按键的扫描代码。
我想要什么:使用这些代码,我将处理并写入有关正在执行的键盘操作的信息。对于不可见的键,我想要格式:“[SHIFT],[ENTER],[ESC]等。 对于可见的键,我想要它们的 Ascii 值(大写和小写) ),包括如果他们输入:!@#$% 等。
我有一些想法,但我不知道如何捕获所有信息,我就是不知道。不知道如何有效地处理它。
I'm making a program that records all the keyboard actions, and stores this information into a log file (Keylogger). I just can't seem to find a good way of doing this.
What I have so far: A LowLevelKeyboardProc, The Virtual Key Code + the Scan Code of the Key being pressed.
What I would like: Using these codes, I will process and write information about the keyboard action being done. For invisible keys I would like the format: "[SHIFT], [ENTER], [ESC], etc. And for visible keys I would simply like their Ascii value (both Upper Case, and Lower Case), including if they enter: !@#$%,etc..
I have a few ideas, but I don't know how I could capture everything. I have the information, I just don't know how to process it efficiently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅我的帖子:其他帖子
我有示例代码如何安装低级键盘挂钩以及如何处理击键。
Refer to my post from here: Other Post
I've got example code for how to install a low-level keyboard hook and how to process the keystrokes.
由于您已经使挂钩正常工作,因此您所需要的只是从键代码到特殊键名称的映射。只需预先填充一个由键代码索引的字符串数组:
然后在钩子函数中,检查键是否是可打印字符,如果是,则直接打印它,否则查找键的名称并打印:
Since you already have the hook working, all you need is a mapping from key codes to names for special keys. Just pre-populate an array of strings indexed by the key code:
Then in your hook function, check if the key is a printable character, if so, print it directly, otherwise lookup the name of the key and print that: