2

My unattended application needs to respond to keystrokes, but only when a specific type of keyboard is attached to the system. It will be a numeric keypad, connected via USB.

I already found out how to detect the connection/disconnection of a keyboard, using libusb/libudev. And it seems than capturing keystrokes from any HID device isn't that hard either, although it requires root privileges, which I'd like to avoid...

Difficulty is that I don't want the Linux system to "use" that numeric keyboard in the normal way, i.e. don't accept input from it on the login tty's. I also don't want to disable logins altogether, login should still be possible using a "regular" keyboard. I have no idea how to do this. Any suggestion is appreciated.

Pat
  • 1,726
  • 11
  • 18
  • If properly configured, `X` will react on `udev` events and load the correct driver when the keyboard gets connected. `libusb` isn't required. However, I don't know how to tell `X` that it should only forward events from *that* keyboard to your application. Interesting question :) +1 – hek2mgl Feb 18 '14 at 20:40
  • @hek2mgl: There is no X installed. The whole system is supposed to operate unattended. – Pat Feb 18 '14 at 21:01
  • Oh, then my comment is a little bit misplaced here. But however, even an unattended system runs udev. you can use udev to notify your application – hek2mgl Feb 18 '14 at 21:04
  • NVM, I found the solution [here][1] [1]: http://stackoverflow.com/questions/7668872/need-to-intercept-hid-keyboard-events-and-then-block-them – Pat Feb 19 '14 at 09:45

1 Answers1

0

I think you are going to have to make the extra keyboard act as a different type of HID device, maybe a different type of device altogether. Then your application can open this special device (which will not be used for normal keyboard input as it's not appearing as a normal keyboard) and accept input from it.

I don't know very much about HID devices except that they seem to cover a very wide range of functionality (for example byte or bit-wide digital I/O), so it should be possible to find a suitable device class.

If you do not have any way of changing how the numeric keypad describes itself to the USB software, you are not going to get anywhere with this, if it says 'I am a keyboard' then it will be treated as a keyboard.

Tim Bergel
  • 499
  • 3
  • 9