Changing the keystrokes of a USB keyboard

徘徊边缘 提交于 2019-12-10 10:58:18

问题


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.

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.

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.

I'm on Windows.


回答1:


I think you are restricting yourself far more than necessary.

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).

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:

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).

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.

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.




回答2:


Well it sounds like you'll need more of a hardware solution than a programming solution. Try this http://www.instructables.com/id/Hacking-a-USB-Keyboard/



来源:https://stackoverflow.com/questions/3706543/changing-the-keystrokes-of-a-usb-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!