I want to write a script that always listens in the background and executes a particular command when the user hits a specific key combination such as Alt + N. How this can be done?
I want to write a script that always listens in the background and executes a particular command when the user hits a specific key combination such as Alt + N. How this can be done?
Download the following python module: showkey.py
Then create a python script (let's call it
test.py
):Put
showkey.py
in your PYTHONPATH or put bothtest.py
andshowkey.py
in the same folder.Run your python script this way:
The
alt_n()
callback will be triggered when the user hits the Alt + N combination. Adapt the handler content for your needs.To know the keycodes (the same codes used by the
showkey
command) to use withshowkey.py
, just run it as a script again withsudo
. All keypress events will be printed in your terminal.