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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.