多个键盘和低级挂钩 [英] Multiple keyboards and low-level hooks

查看:20
本文介绍了多个键盘和低级挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统,我有多个键盘,并且确实需要知道击键来自哪个键盘.解释设置:

I have a system where I have multiple keyboards and really need to know which keyboard the key stroke is coming from. To explain the set up:

  1. 我有一台普通的 PC 和 USB 键盘
  2. 我有一个带有一些硬键的外部 VGA 屏幕
  3. 硬键映射为标准 USB 键盘,发送有限数量的键码(F1、F2、Return、+ 和 -)

我有一个低级挂钩(在 C# 中,但实际上调用 Win32 功能),即使我的应用程序没有获得焦点,它也能够处理输入.

I have a low-level hook (in C# but actually calling upon Win32 functionality) which is able to deal with the input even when my application is not focused.

问题在于,当使用普通键盘时,某些映射的键码会被外部屏幕上驱动的应用程序拾取.外部屏幕发送并用于确认的按键之一是 VK_RETURN.除非我可以识别设备"并对其进行过滤,否则用户可能正在执行操作并在他们甚至没有看的屏幕上确认它们.

The problem is that when using the normal keyboard, some of the mapped key-codes at picked up by the application being driven on the external screen. One of the key-presses sent by the external screen and used for confirmation is VK_RETURN. Unless I can identify the "device" and filter upon it, the user could be performing actions and confirming them on a screen their not even looking at.

我怎么知道是哪个键盘造成了按键?

How do I know which keyboard was responsible for the key-press?

推荐答案

是的,我纠正了,我的错,每天都在学习新的东西.

Yes I stand corrected, my bad, learning something new every day.

这是我弥补它的尝试:):

Here's my attempt at making up for it :) :

  • 使用 ::RegisterRawInputDevices() 注册您想要用于原始输入的设备(两个键盘).

  • Register the devices you want to use for raw input (the two keyboards) with ::RegisterRawInputDevices().

您可以从 GetRawInputDeviceList() 获取这些设备

You can get these devices from GetRawInputDeviceList()

注册设备后,您将开始收到 WM_INPUT 消息.

After you've registered your devices, you will start getting WM_INPUT messages.

WM_INPUT 消息的 lParam 包含一个 RAWKEYBOARD 结构,您可以使用它来确定输入来自的键盘,以及虚拟键码和消息类型(WM_KEYDOWN、WM_KEYUP、...)

The lParam of the WM_INPUT message contains a RAWKEYBOARD structure that you can use to determine the keyboard where the input came from, plus the virtual keycode and the type of message (WM_KEYDOWN, WM_KEYUP, ...)

因此,您可以设置最后一条消息的来源标志,然后将其发送到常规键盘输入处理程序.

So you can set a flag of where the last message came from and then dispatch it to the regular keyboard input handlers.

这篇关于多个键盘和低级挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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