确定来自不同设备的输入 [英] Determine input from different devices

查看:48
本文介绍了确定来自不同设备的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于确定来自不同设备的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆