There is a program called xbindkeys that can bind the mouse and keyboard keys in X to run shell commands. You can either use this to send commands to your program, or look at the source code to see how it is done: xbindkeys
You can also directly open / dev / input / eventX and read () from it to the input_event structure, but this is a bit unpleasant because you need to have the correct permissions (usually root or change them with chmod)
source share