1

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.

2

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
  • 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 '17 at 18:10
  • Do you have $XDG_VTNR variable? – Ipor Sircer Oct 30 '17 at 18:11
  • Then try to figure out which parameters are accepted by chvt. – Ipor Sircer Oct 30 '17 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 '17 at 18:17
  • 1
    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 '17 at 20:59
1

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.

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.