• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

确定来自不同设备的输入

用户头像
it1352
帮助1

问题说明

我的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.

正确答案

#1

在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
系列文章
更多 icon
同类精品
更多 icon
继续加载