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.

3 Answers 3


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:

  • Thanks for your suggestion. I do have the XDG_VTNR environment variable, but the virtual terminal is not responding to Alt+left or Alt+right. If I press either key combination after running xbindkeys -n, I get the following error message: "sudo: no tty present and no askpass program specified".
    – user001
    Oct 30, 2017 at 18:10
  • Do you have $XDG_VTNR variable? Oct 30, 2017 at 18:11
  • Then try to figure out which parameters are accepted by chvt. Oct 30, 2017 at 18:15
  • The chvt command works (e.g., if I type sudo chvt $(($XDG_VTNR+1)) into xterm, then my VT changes appropriately), so the problem is upstream (at thexbindkeys step).
    – user001
    Oct 30, 2017 at 18:17
  • 2
    The problem was that the line in sudoers had to be at the end of the file. The standard line %sudo ALL=(ALL:ALL) ALL was apparently overriding the settings.
    – user001
    Oct 30, 2017 at 20:59

One thing that remains constant as you switch from VT to X11 and back is the "low-level" generic Linux input device handling subsystem. There are examples in C in Linux USB Input Subsystem and part 2 in Linux Journal. Your system may have a Python library python-evdev package to make this easier.

To try out what is possible, evtest can be used to simply dump the events on a given input device, and you can track the state of the keys that interest you with an awk script or similar, and get it to issue the chvt commands.


The Alt+Arrow keys become available to you if you are in XLATE mode. If you are not, you can activate it by using the magic sysrq key: an escape hatch in your kernel for when X locks up.

First, make sure it is on:

cat /proc/sys/kernel/sysrq

The output is a number, and you can switch into XLATE if it is either 1, or bitmask 0x4 is set: x == 1 || x & 0x4. Source

If neither is true you can change the number as root:

echo 1 > /proc/sys/kernel/sysrq

On Arch Linux I can alternatively do:

sysctl kernel.sysrq=1

Finally, either press Alt+SysRq+R or run the command below:

echo r > /proc/sysrq-trigger

You are now in XLATE mode- you have been blessed with handy key bindings until you reboot! For possible side effects, see this.

Somebody please tell me if you can turn this on permanently.

You must log in to answer this question.

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