On my computer I have two USB keyboards plugged in. Instead of having both just type the same key, is it possible for a second keyboard to be setup to run commands instead of typing letters? And If that's not possible, can it be setup to at least type in another language like Russian for example?
Second Keyboard – How to Use for Running Commands
keyboard
Related Solutions
Disable device
Here's one idea towards identifying which keyboard is which. You can use the command xinput to enable and disable devices.
Example
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)]
⎜ ↳ TPPS/2 IBM TrackPoint id=13 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=9 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=10 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=11 [slave keyboard (3)]
↳ ThinkPad Extra Buttons id=14 [slave keyboard (3)]
The above output shows the various devices that I have on my Thinkpad laptop. I only have 1 keyboard attached, this one:
↳ AT Translated Set 2 keyboard id=11 [slave keyboard (3)]
Now take a look at the properties available through this device:
$ xinput list-props "AT Translated Set 2 keyboard"
Device 'AT Translated Set 2 keyboard':
Device Enabled (124): 1
Coordinate Transformation Matrix (126): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.
From the above you can see that it's enabled, so let's disable it:
$ xinput set-prop "AT Translated Set 2 keyboard" "Device Enabled" 0
To enable it:
$ xinput set-prop "AT Translated Set 2 keyboard" "Device Enabled" 1
The idea?
You could enable disable one of the keyboards using this command to determine which one you're on.
References
This will probably take several steps/iterations, and the Q&A format isn't a good fit. Please update your question with more information if you are stuck, and ping me in a comment to this answer. I'll edit my answer then.
From the description it sounds like the mapping of special keys to key events is done in the keyboard, so programming must happen in the keyboard, and not in a driver.
There are various open source USB sniffer for Windows, e.g. usbpcap or the older usbsnoop, google will probably find more, and tutorials how to use them.
In principle, you'll need to record the communication while programming different special keys with different key sequences with the programming software. Then look at the packets, compare them, and see which bytes change for different special keys or programmed sequences. Guess the protocol, replay it in a self-written program using libusb
on Linux.
As your keyboard is HID, and HID is highly standardized, we have a bit of help. Familiarize yourself with the HID documentation (or at least look up those parts you need). Each HID device comes with a descriptor, and the descriptor describes all possible interaction with the device according to the HID standard. If this is how the keyboard is programmed, and if there are not too many "vendor-specific" fields, we may guess the protocol directly.
You can read the descriptor in two ways.
(1) If your kernel has debugfs
enabled, as root do
mount -t debugfs none /sys/kernel/debug
cat /sys/kernel/debug/hid/device_id/rdesc
where device_id
is the id if your keyboard. This will show the raw descriptor as hex bytes, and how the kernel parses it. If the kernel parse is not enough, try hidrd to convert the raw descriptor.
(2) Issue HIDIOCGRDESCSIZE
and HIDIOCGRDESC
ioctls on the hidraw
device (look in dmesg
to find it for your keyboard). The samples/hidraw/hid-example.c
in the Linux kernel source explains how to do that, or use a ready-made tool like usbhid-dump.
Ideally you'll see some feature or output description(s) that is/are related to the programming. You may still have to snoop the software tools if too many of the described fields are unclear or marked "vendor-specific".
Best Answer
This is my third answer when I can recommend
actkbd
... :)So if you want to configure all keys of second keyboard to run commands not to type letters you can use
actkbd
... :)After installing
actkbd
we need to find what device file is used to receive events from out keyboard:On this list you should find your keyboard, and check it handlers. Use
sudo actkbd -s -d /dev/input/HANDLER_NAME
to check if that handler send events. If you run this command and press key on keyboard (check for keys that you want to bind to commands) you should get something like that:If you have keycodes we could create
actkbd
config file:When you save that file we should test if configuration works:
When you press key that you have in your config file command from last column of config file will be started.
I think that there is a way to disable sending keys to applications, but I was unable to find it - check out README file.
Instead of trying to disable it using
actkbd
you could turn off your keyboard in X.It should do the work... :) For more information about
actkbd
check out this answer.Using
actkbd
(and few scripts probably) you can also configure your keyboard to change modes from command mode to input mode with Russian letters. For this readUlrich Schwarz's
answer.