X11 – Key Binding to Increment/Decrement Virtual Console

keyboard shortcutsvirtual-consolesx11

One can change virtual consoles (or virtual terminals, VTs) by pressing Ctrl+Alt+Fn (where Fn represents F1, F2, etc.). In addition, when not running X, one can press Alt and the arrow keys to cycle through VTs (Alt to decrement and Alt to increment the virtual terminal).

However, if X is running on one of the VTs, the arrow key bindings are not typically set and one must fall back to Ctrl+Alt+Fn to change to another VT.

I generally prefer using the arrow bindings to change VTs. To avoid having to switch between key bindings (Ctrl+Alt+Fn for VTs with X; arrows for VTs without it), to what command would one bind Alt←/→ for decrementing/incrementing the VT in X?

In case the answer depends on the system, I am running debian and using dwm and openbox as window managers.

Best Answer

I can only tell you a dirty workaround. Use xbindkeys and add to ~/.xbindkeysrc:

"sudo chvt $(($XDG_VTNR-1))"
   alt + c:113

"sudo chvt $(($XDG_VTNR+1))"
   alt + c:114

If you don't have XDG_VTNR variable, then you have to hardcode previous/next vt.

You also have to put yourself into /etc/sudoers:

USER ALL=NOPASSWD:/bin/chvt
Related Question