I once wrote a python program to trigger callback functions when specific keys on my MIDI keyboard are pressed. The MIDI protocol was surprisingly simple to figure out (for simple things like "button-x was pressed at 25% pressure" anyway). It had a learning mode where you assign a key by pressing it and an action mode where pressing the assigned keys would trigger functions to be called.
I had intended to use it as a shortcut panel to run a shell scripts, but never actually finished it.. might do so sometime soon :-)