[英]How to differentiate between a keypress of more than one usb-keyboard connected to the same host (in C#)
I need to differentiate between a keypress of (at least) two usb-keyboards connected to a single PC.我需要区分连接到一台 PC 的(至少)两个 USB 键盘的按键。 Is there a method/precedure available to decide if key 's' (for example) is pressed either by keyboard A or Keyboard B?
是否有可用的方法/程序来决定键“s”(例如)是由键盘 A 还是键盘 B 按下? (preferable language is C#)
(首选语言是 C#)
Pseudo-Code:伪代码:
if (keyPressed == 's')
{
if(keyboardID == 'A')
{
print("Key 's' was pressed by Keyboard A");
}
else if (keyboardID == 'B')
{
print("Key 's' was pressed by Keyboard B");
}
}
keystrokes are processed by the OS as events击键由操作系统作为事件处理
in linux for every input device there is separate event queue in /dev/input/event*
( *
means the specific device number)在 linux 中,对于每个输入设备,
/dev/input/event*
都有单独的事件队列( *
表示特定的设备编号)
in linux you can list all input devices with the command sudo lsinput
(input-utils)在 linux 中,您可以使用命令
sudo lsinput
(input-utils) 列出所有输入设备
you can capture the specific events for each of your keyboards, see Linux keyboard event capturing /dev/inputX您可以捕获每个键盘的特定事件,请参阅Linux 键盘事件捕获 /dev/inputX
in windows this is similar.在 Windows 中,这是类似的。 you can use
rawInput
and get a handle for each device.您可以使用
rawInput
并获取每个设备的句柄。 deeper information and example codes is in更深入的信息和示例代码在
https://blogs.msdn.microsoft.com/oldnewthing/20160627-00/?p=93755 (" The device handle tells us which keyboard generated the input ... ") https://blogs.msdn.microsoft.com/oldnewthing/20160627-00/?p=93755 (“设备句柄告诉我们哪个键盘生成了输入......”)
https://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard https://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard
raw input handling (distinguishing secondary mouse) 原始输入处理(区分辅助鼠标)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms645543%28v=vs.85%29.aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms645543%28v=vs.85%29.aspx
Short of getting to the driver level and intercepting the keystroke there, you really can't (I think).没有到达驱动程序级别并在那里拦截击键,你真的不能(我认为)。 I utilize a bluetooth keyboard and a bluetooth keypad and could not find a way to do what you are asking so the number 3 on the keypad would register different than the number 3 on the keyboard keypad.
我使用蓝牙键盘和蓝牙小键盘,但找不到方法来执行您的要求,因此小键盘上的数字 3 与键盘小键盘上的数字 3 不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.