获取所有按下的按键
那么是否有可能在任何应用程序的任何地方按下所有按键?或多或少像一个键盘记录器。我想知道这在 C++ 或 C# 中是否可行。
问候
So is there possible to intersect all keys pressed everywhere, where everywhere is at any application? More or so like a keylogger. I was wondering if that is possible in C++ or C#.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找的是键盘挂钩。使用一些 P/Invoke 可以实现这一点。请参阅此处的示例:
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
What you're looking for is a Keyboard Hook. This is possible using some P/Invoke. See sample here:
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
如果您想使用 winapi thaen 函数,您正在寻找带有 WH_KEYBOARD 标志的
SetWindowsHookEx
。如果你想获得真正的所有kes,你可以使用low-lewel标志代替WH_KEYBOARD_LL
,但这不会翻译击键,所以它更难使用。我从未使用过这个标志,但我知道某些标志需要在单独的模块(例如 dll)中注册钩子函数,因为它们将在实际接收键盘输入的应用程序上下文中加载和执行。如果是这样,您还必须考虑一种将收集的数据返回到应用程序的机制,因为全局变量将不起作用。
If you want to use winapi thaen function you are looking for is
SetWindowsHookEx
with flag WH_KEYBOARD. If you want to get really all kes you might use low-lewel flag insteadWH_KEYBOARD_LL
, but this will not translate keystrokes, so it's more difficult to work with.I never used this flag, but i know that some flags need registered hook function to be in separate module (eg. dll) as they will be loaded and executed executed in context of application that actually recieves keyboard input. If it is so you must also think of a mechanism of returning colected data back to your application, cause global variables will not work.