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

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

问题描述

我有一个系统,我有多个键盘和真正需要知道的击键来自哪个键盘。为了解释设定:

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键盘,发送键盘codeS的数量有限(F1,F2,返回,+和 - )

我有一个低级别挂钩(在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.

的问题是,使用普通键盘时,一些映射键盘codeS中的由应用程序被在外部屏幕上驱动拾取。一个接外屏发送,用于确认键盘presses是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.

我怎么知道哪个键盘是负责该键盘preSS?

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中包含您可以用它来确定输入来自的键盘,再加上虚拟键code和消息的类型(WM_KEYDOWN,WM_KEYUP一个RAWKEYBOARD结构,.. 。)

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天全站免登陆