joyd is a very flexible program that allows you to execute commands via a joystick or joypad attached to your computer. One simple possibility would be to reboot when your keyboard is hung. It can use any device supported by the Linux Joystick Driver. Helper applications allow you to test the joystick status in your own shell scripts.