Command line tools: Detect and configure keyboards

Last modified on 2017-06-27

I have two keyboards I am interested in modifying with custom hotkey actions (via xbindkeys) and remapping keys (via xmodmap). For my laptop’s keyboard I created .xbindkeysrc.chromebook and .xmodmap.chromebook, my Thinkpad USB Keyboard + Trackpoint uses .xbindkeysrc.thinkpad_usb and .xmodmap.thinkpad_usb, and I create ~/.xbindkeysrc and ~/.xmodmap symlinks to the relevant config for the keyboard in use.

Now that the laptop is my primary machine, I may be using either keyboard on the same machine depending on location: the built-in keyboard when away; connecting to the USB keyboard and external display when at home. Old method of symlinking won’t work if I am switching which keyboard I use.

[ FIX! ] I created the keyboardconf shell script to detect attached keyboards and load appropriate modifications. Priority is assigned to the external Thinkpad keyboard and, failing to detect that device, the program falls back to setting up the built-in keyboard. Scripting this detection makes it easy for me to add more keyboard types in the future!

Program is in my ~/bin and I add the command to ~/.xinitrc to run at startx

~/bin/keyboardconf &

🐧 Part of the HOME slash bin project.

Happy hacking!