我可以同时使用全局挂钩和原始输入吗?
我尝试使用 Global Hooks 使用 SetWindowsHookEx
来获取所有击键。
问题是我无法同时使用全局挂钩和原始输入。
我认为这里一定存在一些问题,因为在启用原始输入后全局挂钩会自动禁用。
I tried using Global Hooks using SetWindowsHookEx
to get all the the keystrokes.
Problem is i cant use Global Hooks and Raw Input at the same time.
I'm thinking there must be some issue here because the Global Hooks automatically gets disabled after I enable Raw Inputs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谁告诉你它们需要一起使用的?如果您的应用程序注册为处理原始输入,则绝对没有理由安装全局挂钩。原始输入模型的全部要点是让应用程序接收来自连接到计算机的任何 HID 的通知并处理原始输入。
相反,您侦听
WM_INPUT
消息 ,它会发送到您通过调用RegisterRawInputDevices
函数。收到此消息后,您的应用程序应调用GetRawInputData
使用WM_INPUT
消息的lParam
参数中包含的RAWPUT
句柄调用函数。示例代码位于此处。或者,您可以对原始数据进行缓冲读取。这对于一次生成大量输入的设备更有用。通过这种方法,您可以调用
GetRawInputBuffer
函数,它返回一个RAWPUT
结构数组。同样,示例代码可在此处获取。有关原始输入函数的主题阅读位于 MSDN 上。
Who told you that they needed to be used together? If your application is registered to handle raw input, there's absolutely no reason to install a global hook. The whole point of the raw input model is for an application to receive notification of and process raw input from any HID connected to the computer.
Rather, you listen for the
WM_INPUT
message, which is sent to the application's message queue for any HID that you've registered by calling theRegisterRawInputDevices
function. Upon receipt of this message, your application should call theGetRawInputData
function using theRAWINPUT
handle contained in thelParam
parameter of theWM_INPUT
message. Sample code is available here.Alternatively, you can do a buffered read of the raw data. This is more useful for devices that generate large amounts of input at a time. With this approach, you call the
GetRawInputBuffer
function, which returns an array ofRAWINPUT
structures. Again, sample code is available here.Topical reading on the Raw Input functions is here on MSDN.
您不需要对已由 LRESULT WindowProcedure 回调检查过的原始输入进行挂钩。如果使用了诸如 mouse_pos、mouse_click(以及可以通过计数器确定的点击次数)、key_input 等设备,您只需要获取信息...
You don't need a hook for the raw input which already checked by the LRESULT WindowProcedure callback. You just need to get the information back if a device was used like a mouse_pos, mouse_click (and its number of clicks which you can determine by a counter), key_input, etc...