确定来自不同设备的输入
问题说明
我的PC上有两个设备,例如键盘,普通键盘和HID( H uman I i D evice)输入设备(这是一个遥控器).
My PC has two devices working like keyboard, the normal keyboard and a HID (Human Interface Device) input device (it's a remote control).
我想将输入与键盘和遥控器分开,仅捕获遥控器.如何用C/C 编写程序来完成此任务?
I want separate the input from keyboard and from remote, capturing only the remote control. How can I write a program in C/C to do this task?
这不是一件容易的事,因为该程序取决于操作系统.我在Windows上需要它,但是如果有人知道如何在Linux上使用它,我也将不胜感激.
It's not a easy task because this program is operating system dependent. I need it for Windows, but if someone knows how to do it for Linux, I would appreciate that too.
正确答案
在Windows XP和更高版本上,您可以使用原始输入设备消息.首先,您调用 RegisterRawInputDevices()
API函数以为键盘"启用原始输入.您调用 GetRawInputDeviceList()
枚举输入设备并找到与您的遥控器相对应的句柄.然后,您处理包含原始输入事件的WM_INPUT窗口消息,并检查附加的RAWINPUT结构的标头,以查看源设备句柄是否与您之前获得的句柄匹配.如果是这样,您可以继续处理事件.
On Windows XP and later you can use raw input device messages. First you call the RegisterRawInputDevices()
API function to enable raw input for "keyboards". You call GetRawInputDeviceList()
to enumerate input devices and find the handle corresponding to your remote. Then you process the WM_INPUT window messages which contain raw input events, and check the header of the attached RAWINPUT structure to see whether the source device handle matches the handle you got earlier. If it does, you can continue processing the event.
请注意RIDEV_INPUTSINK标志,这可能对您有用.如果指定它,则即使您的窗口不是前台窗口,它也会使窗口接收事件的WM_INPUT消息.
Note the RIDEV_INPUTSINK flag, which may be useful to you. If you specify it, it makes your window receive WM_INPUT messages for events even if it is not the foreground window.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfijjk
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20