Is there any way of configuring keyboard shortcuts in the Linux virtual console?
For example, if I go to tty1 then press the key combination Ctrl+Alt+H, I would like the script
/usr/bin/hello.sh to be executed.
Ideally, the shortcut would be available even before logging in (in which case it would be executed with the privileges of a user that I specify). I don't mind modifying the kernel either, if that's the only way of accomplishing this. Also, it doesn't have to be a shell script, it can also be a normal ELF binary or even a kernel module making system calls.
Example use cases
- I'm in the console and browsing the web with something like
linksand I want to turn down the screen brightness. I press Fn+End, which happens to be the brightness down key and produces a single keycode, and a program runs which reduces the brightness by writing something in a
- I'm in a console text editor and listening to some music in the background that's being played by
mpd. I press the ⏯ (play/pause) key, which again produces a single keycode, and that has the effect of executing a program which sends a signal to
mpdto pause the current song.
Following dirkt's idea of using
/dev/input, I created evd (event daemon) for this purpose. The application can be started in the background and will take over the keyboard wherever you are, including before login and within X.