Find the deviceID first, using xinput list
$ xinput list
⎣ Virtual core keyboard
...
↳ USB Keyboard id=19 [slave keyboard (3)]
key mapping per device/keyboard
(This will only map keys. See below for mapping scripts to keys)
setxkbmap has the option to target a specific device (keyboard).
Then query the setxkbmap config to see your device settings (I will use '19'):
$ setxkbmap -device 19 -print
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us(euro)+us(intl):2+inet(evdev)" };
xkb_geometry { include "pc(pc105)" };
};
The symbols is what we're looking for; these can be found in ls /usr/share/X11/xkb/symbols. The arguments refer to a subsection in the file, for example xkb_symbols "intl" {
To add any of the available options like for example, rupeesign, you
could do setxkbmap -device 19 -option rupeesign:4
to reset the options, use setxkbmap -device 19 -option without further arguments.
However, you want some custom configuration, and that is a bit more tricky, because simply adding a custom file in that folder and using it does not work.
So create some folders and create a tempfile with the current config.
mkdir -p ~/.config/xkb/symbols
cd ~/.config/xkb
setxkbmap -device 19 -print > tempfile.txt
touch symbols/mysymbol
Edit tempfile.txt so it contains mysymbol(mymapping)
...
xkb_symbols { include "pc+us(euro)+us(intl):2+inet(evdev)+mysymbol(mymapping)"
Edit symbol/mysymbol any way you want, see /usr/share/X11/xkb/symbols for examples.
This one adds a Bitcoin symbol to num 7 key .
partial
xkb_symbols "mymapping" {
key <AE07> { [ 7, &, U20BF ] };
};
Now, finally, to activate this mapping, use xkbcomp ( note -i 19 to set the device)
xkbcomp -i 19 -I$HOME/.config/xkb tempfile.txt $DISPLAY
(This will probably show some warning messages, but it still works)
Mapping keys to start a script
There is a tool for mapping key to a script: actkbd
install:
$ git clone https://github.com/thkala/actkbd
$ cd actkb
$ make
$ sudo make install
Then find the devicename for your keyboard in /dev/input/,
in my case it is /dev/input/by-id/usb-_USB_Keyboard-event-kbd
You should now have a config file /etc/actkbd.conf containing some examples, can all be all be removed. Here are some more practical examples
# 'a' starts gedit
30:::gedit
# 'shift+7' starts a custom script. (keynumber 8 for some reason)
42+8:::/home/me/myscript.py
To find the keynumber (or keycombination), use the 's' option:
$ actkbd -d /dev/input/by-id/usb-_USB_Keyboard-event-kbd -s
After your configuration in /etc/actkbd.conf, start the program (use -D for background mode )
$ actkbd -d /dev/input/by-id/usb-_USB_Keyboard-event-kbd