更改USB键盘的击键 [英] Changing the keystrokes of a USB keyboard

查看:170
本文介绍了更改USB键盘的击键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次在常规键盘上按下一个键时,都会向计算机发送数字键代码",例如.代表特定键的32或51.

Every time a key is pressed on a regular keyboard, a numeric 'key code' is sent to the computer, eg. 32 or 51 which represent specific keys.

与我用来键入此帖子的默认键盘无关,我希望能够通过USB插入键盘并将其键代码全部上移某个常数C.

Unrelated to my default keyboard which I am using to type this post, I want to be able to plug in a keyboard via USB and have its key codes all shifted up by some constant C.

因此,当按下此侧面键盘上的"a"键时,计算机将不会收到"a"的键码,而是会收到一些更高的数字,而计算机对此没有计划的响应.

Thus, when pressing the 'a' key on this side keyboard, the computer would not receive the keycode for 'a', but rather some higher number which the computer does not have a planned response to.

这些超出常规范围的击键将控制我的程序,该程序知道它们是什么并且正在监听它们.

These out-of-conventional-range keystrokes will control a program of mine which knows what they are and will be listening for them.

硬件或软件解决方案将对我有用.也许为此目的出售了特殊的键盘,或者也许与软件相关的一些修改可以让任何常规键盘都可以做到这一点-我不知道.至关重要的是,键码转换仅适用于我的侧键盘,而不适用于我用于常规操作的默认键盘.

Hardware or software solution would work for me. Perhaps there are special keyboards sold for this end, or maybe some software-related modification could let this be accomplished for any regular keyboard-- I have no idea. What is crucial is that the keycode shift applies only for my side keyboard and not my default keyboard which I use for regular stuff.

我在Windows上.

I'm on Windows.

推荐答案

我认为您对自己的限制远远超出了必要.

I think you are restricting yourself far more than necessary.

对于初学者来说,您对USB键盘的描述已大大简化.情况要复杂得多.例如,您实际上获得了按下/按下序列. (也称为成败).

For starters, your description of USB keyboards is simplified a lot. The situation is a bit more complex than that. For instance, you actually get key-down/key-up sequences. (Also known as make and break).

接下来的事情是,您要假设操作系统对键盘的处理方式.如果第二个键盘声称它是USB键盘,则将由USB键盘的OS驱动程序处理.那将不会期望值发生变化.例如,在Microsoft Windows上,记录了以下行为:

The next thing is that you're making assumptions about the handling of the keyboard by the OS. If the second keyboard claims it's an USB keyboard, it will be handled by the OS driver for USB keyboards. That will not expect shifted values. For instance, on Microsoft Windows, the following behavior is documented:

避免设置1个0x79以上的扫描代码, 因为发布(按键)代码将 为0xFA或更大,并且键盘 已知驾驶员会解释这种情况 值作为来自8042的响应 芯片,而不是按键(扫描代码).

Avoid Set 1 scan codes above 0x79, since the release (key up) code would be 0xFA or greater, and the keyboard driver is known to interpret such values as responses from the 8042 chip, not as keystrokes (scan codes).

接下来,操作系统将假定一个额外的键盘将提供额外的密钥,并直接对其进行处理.例如,笔记本电脑有可用的数字USB键盘,而Windows只是将它们视为额外的0-9 +-/* =键.不在乎它们是否在单独的硬件上.基本上,我认为第二个keayboard想法不会成功.

Next, an OS will assume that an extra keybaord will provide extra keys, and handle it directly. For instance, there are numeric USB keyboards available for laptops, and Windows just treats them as extra 0-9+-/*= keys. It doesn't care that they're on separate hardware. Basically, I don't think this second keayboard idea will fly.

现在,USB通常将键盘视为更通用的类的特例,这种情况更为灵活:HID = 人类输入设备. .例如,USB游戏杆也是人为输入设备,典型的操作系统不会尝试解释游戏杆按钮.预计游戏将直接处理它们,您的应用也会如此.

Now USB usually treats keyboard as a special case of a more generic class, which is more flexible: HID = Human Input Devices. . For instance, USB joysticks are also Human Input Devices, and a typical OS doesn't try to interpret joystick buttons. Games are expected to handle them directly, and so could your app.

这篇关于更改USB键盘的击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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