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
links
and 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/sys
file. - 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 tompd
to pause the current song.
Solution
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.
readline
macros might be what you're looking for, and once configured will work anywhere you use bash (or a similarly readline-capable shell) rather than only in the console. see wiki.archlinux.org/index.php/readline#Macros – quixotic Jul 13 '18 at 15:35/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt? – roaima Jul 13 '18 at 15:44readline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alikegetty
replacements. – quixotic Jul 14 '18 at 4:37