Keyboard shortcuts in the virtual terminal
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
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 ksd (keyboard shortcuts 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.
linux terminal keyboard-shortcuts tty
 |Â
show 2 more comments
up vote
6
down vote
favorite
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 ksd (keyboard shortcuts 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.
linux terminal keyboard-shortcuts tty
1
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 at 15:35
Do you want the script to be executed invisibly, or the line/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?
â roaima
Jul 13 at 15:44
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
2
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@rid yes, that would be a limitation of areadline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alikegetty
replacements.
â quixotic
Jul 14 at 4:37
 |Â
show 2 more comments
up vote
6
down vote
favorite
up vote
6
down vote
favorite
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 ksd (keyboard shortcuts 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.
linux terminal keyboard-shortcuts tty
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 ksd (keyboard shortcuts 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.
linux terminal keyboard-shortcuts tty
edited Jul 16 at 5:01
asked Jul 11 at 8:47
rid
13017
13017
1
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 at 15:35
Do you want the script to be executed invisibly, or the line/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?
â roaima
Jul 13 at 15:44
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
2
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@rid yes, that would be a limitation of areadline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alikegetty
replacements.
â quixotic
Jul 14 at 4:37
 |Â
show 2 more comments
1
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 at 15:35
Do you want the script to be executed invisibly, or the line/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?
â roaima
Jul 13 at 15:44
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
2
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@rid yes, that would be a limitation of areadline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alikegetty
replacements.
â quixotic
Jul 14 at 4:37
1
1
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 at 15:35
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 at 15:35
Do you want the script to be executed invisibly, or the line
/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?â roaima
Jul 13 at 15:44
Do you want the script to be executed invisibly, or the line
/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?â roaima
Jul 13 at 15:44
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
2
2
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@rid yes, that would be a limitation of a
readline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alike getty
replacements.â quixotic
Jul 14 at 4:37
@rid yes, that would be a limitation of a
readline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alike getty
replacements.â quixotic
Jul 14 at 4:37
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Partial answer (because it's just an outline, and untested):
Write a demon which listens to whatever /dev/input
device corresponds to your main keyboard (there are symlinks, look at them). Start that demon as the user you specify, using whatever init system you have (systemd, sysv, whatever).
The demon processes key events as defined in input-events-codes.h (or look at the source code of evtest
). It has a state machine that recognizes your desired key sequences, and spawns whatever process you specify when such a sequence is complete.
This should be available before you login, and will always execute as the same user, no matter what user you are logged in at the virtual console. It will also execute under X, again as the same user.
Alternative, if you want to execute something in a shell: Use tmux
or a similar program which can bind key sequences to actions. I suppose it should also be possible to automatically start tmux
and attach to a new session whenever you log in at a virtual console, but I haven't looked into that.
This won't work before log in, but will also work in graphical terminal emulators that have keyboard focus, and will execute the script as the user which is logged in.
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using/dev/input
and/dev/uinput
.
â rid
Jul 16 at 4:58
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Partial answer (because it's just an outline, and untested):
Write a demon which listens to whatever /dev/input
device corresponds to your main keyboard (there are symlinks, look at them). Start that demon as the user you specify, using whatever init system you have (systemd, sysv, whatever).
The demon processes key events as defined in input-events-codes.h (or look at the source code of evtest
). It has a state machine that recognizes your desired key sequences, and spawns whatever process you specify when such a sequence is complete.
This should be available before you login, and will always execute as the same user, no matter what user you are logged in at the virtual console. It will also execute under X, again as the same user.
Alternative, if you want to execute something in a shell: Use tmux
or a similar program which can bind key sequences to actions. I suppose it should also be possible to automatically start tmux
and attach to a new session whenever you log in at a virtual console, but I haven't looked into that.
This won't work before log in, but will also work in graphical terminal emulators that have keyboard focus, and will execute the script as the user which is logged in.
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using/dev/input
and/dev/uinput
.
â rid
Jul 16 at 4:58
add a comment |Â
up vote
2
down vote
accepted
Partial answer (because it's just an outline, and untested):
Write a demon which listens to whatever /dev/input
device corresponds to your main keyboard (there are symlinks, look at them). Start that demon as the user you specify, using whatever init system you have (systemd, sysv, whatever).
The demon processes key events as defined in input-events-codes.h (or look at the source code of evtest
). It has a state machine that recognizes your desired key sequences, and spawns whatever process you specify when such a sequence is complete.
This should be available before you login, and will always execute as the same user, no matter what user you are logged in at the virtual console. It will also execute under X, again as the same user.
Alternative, if you want to execute something in a shell: Use tmux
or a similar program which can bind key sequences to actions. I suppose it should also be possible to automatically start tmux
and attach to a new session whenever you log in at a virtual console, but I haven't looked into that.
This won't work before log in, but will also work in graphical terminal emulators that have keyboard focus, and will execute the script as the user which is logged in.
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using/dev/input
and/dev/uinput
.
â rid
Jul 16 at 4:58
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Partial answer (because it's just an outline, and untested):
Write a demon which listens to whatever /dev/input
device corresponds to your main keyboard (there are symlinks, look at them). Start that demon as the user you specify, using whatever init system you have (systemd, sysv, whatever).
The demon processes key events as defined in input-events-codes.h (or look at the source code of evtest
). It has a state machine that recognizes your desired key sequences, and spawns whatever process you specify when such a sequence is complete.
This should be available before you login, and will always execute as the same user, no matter what user you are logged in at the virtual console. It will also execute under X, again as the same user.
Alternative, if you want to execute something in a shell: Use tmux
or a similar program which can bind key sequences to actions. I suppose it should also be possible to automatically start tmux
and attach to a new session whenever you log in at a virtual console, but I haven't looked into that.
This won't work before log in, but will also work in graphical terminal emulators that have keyboard focus, and will execute the script as the user which is logged in.
Partial answer (because it's just an outline, and untested):
Write a demon which listens to whatever /dev/input
device corresponds to your main keyboard (there are symlinks, look at them). Start that demon as the user you specify, using whatever init system you have (systemd, sysv, whatever).
The demon processes key events as defined in input-events-codes.h (or look at the source code of evtest
). It has a state machine that recognizes your desired key sequences, and spawns whatever process you specify when such a sequence is complete.
This should be available before you login, and will always execute as the same user, no matter what user you are logged in at the virtual console. It will also execute under X, again as the same user.
Alternative, if you want to execute something in a shell: Use tmux
or a similar program which can bind key sequences to actions. I suppose it should also be possible to automatically start tmux
and attach to a new session whenever you log in at a virtual console, but I haven't looked into that.
This won't work before log in, but will also work in graphical terminal emulators that have keyboard focus, and will execute the script as the user which is logged in.
edited Jul 16 at 5:17
answered Jul 14 at 7:49
dirkt
13.8k2930
13.8k2930
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using/dev/input
and/dev/uinput
.
â rid
Jul 16 at 4:58
add a comment |Â
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using/dev/input
and/dev/uinput
.
â rid
Jul 16 at 4:58
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using
/dev/input
and /dev/uinput
.â rid
Jul 16 at 4:58
That's exactly what I was looking for, thank you. I created ksd (keyboard shortcuts daemon) using
/dev/input
and /dev/uinput
.â rid
Jul 16 at 4:58
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454645%2fkeyboard-shortcuts-in-the-virtual-terminal%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
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 at 15:35
Do you want the script to be executed invisibly, or the line
/usr/bin/hello.sh
to be entered into the keyboard buffer as if you'd typed it at the shell prompt?â roaima
Jul 13 at 15:44
@roaima, I would like the script to be executed invisibly, ideally 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 be a normal ELF binary as well.
â rid
Jul 13 at 22:48
2
@quixotic, unfortunately that only works at the bash prompt. I would like the shortcut to be available regardless of what program I'm currently in.
â rid
Jul 13 at 22:50
@rid yes, that would be a limitation of a
readline
solution. i think it's the closest you'll find in existing implementations; i'm unaware of multitasking desktop-alikegetty
replacements.â quixotic
Jul 14 at 4:37