I'm wondering if it's possible to adjust (increment/decrement) brightness or volume with a laptop keyboard's dedicated brightness/volume keys in the virtual console.

Can the system be configured to perform a background operation in response to a single keypress, or is the only mode of interaction via the command line? (I have already found ways to make the adjustments via the command line.)

The only comparable example I can think of is the power button signaling an immediate system halt. However, I suspect that operates on a different level, since when I tried pressing it at the showkey prompt, it still shut down the system (rather than returning a keycode).

EDIT: Actually, while I've figured out how to do these things purely by the command line, I haven't figured out how to do them without root access. Any further insight on the matter would be greatly appreciated.

3 Answers 3


It depends on which shell you use in your tty, but generally: Yes, you can. The readline library is the software component that makes these keyshortcuts possible.

I only happen to know how it works with zsh, so I'll give an example with it. In case you use bash, try reading the "Readline Key Bindings" section in the manual - it looks like this is what you're looking for.

With zsh:

myfunc() {
    echo 'It works!'
zle -N mywidget myfunc
bindkey "^[OQ" mywidget

The zle -N command is used to define something called a "zsh widget". Widgets can be used to call functions. The bindkey command let's you specify a keycode and a widget that will be executed whenever the key is pressed. The keycode ^[OQ happens to refer to the F2 key in my case. To find out what keycode your volume key has, press Ctrl+V and then hit the volume key (in my case, I would hit Fn+F2, which gives me ^[[26~).


This is not a generalized solution to the problem, but after a couple days of troubleshooting, I discovered pommed, which is specifically for managing hotkeys on Apple laptops (which is what I have).

In addition to allowing you to increment/decrement brightness/keyboard backlight/audio volume, it also automatically sets brightness when AC power is connected/disconnected (among other things). Way nicer than trying to write my own scripts for it.


Have you looked at and tried this: https://wiki.archlinux.org/index.php/Linux_console/Keyboard_configuration ?

You need to create a custom(ized) virtual console keymap. (This is in Arch. I guess it's different in Debian/Ubuntu and maybe others as well.)

By means of showkey entered on the virtual console you'll determine the keycode number (you can do this by xev under Xorg, but need to deduct 8 to get the console keycode number, that is, if xev gives you 169 it means 161 for your console keymap).

For instance, while I'm in a tty, by this custom keymap I can change to the next console by just pressing the eject key on my (Apple) keyboard in an Arch/Fluxbox system:

keycode 161 = Incr_Console   Last_Console     Decr_Console
        shift   altgr   keycode 161 = VoidSymbol
        altgr   control keycode 161 = VoidSymbol
        shift   altgr   control keycode 161 = VoidSymbol
        shift   alt     keycode 161 = VoidSymbol
        altgr   alt     keycode 161 = VoidSymbol
        shift   altgr   alt     keycode 161 = VoidSymbol

Shift+Eject goes to the last console and Ctrl+Eject decreases it.

For volume and brightness you may need an extra step.

Let's say your keycode number is 161 then first bind it to an unused function key, F70 for instance:

keycode 161 = F70

Then bind that F70 to a command string:

In order to execute a printed command in a terminal, a newline escape character must be appended to the end of the command string. For example, to enter a system into hibernation, the following keymap is added:

string F70 = "sudo /usr/sbin/hibernate\n"

If this fails you might examine acpid.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .