Detect and configure keyboards

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

Now that Stretchbook 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 &

Sources: homebin/keyboardconf, dotfiles/.xbindkeysrc.chromebook, dotfiles/.xmodmap.chromebook, dotfiles/.xbindkeysrc.thinkpad_usb, dotfiles/.xmodmap.thinkpad_usb, and dotfiles/.xinitrc

Happy hacking!

More • keyboardshellprogramminghomebinlinux