Where are keypresses in the terminal being handled/captured? If I want to modify the behaviour of the Alt + F# key combinations (to swithc vterms), where is this key combination being handled?
The console switching functions in the kernel's virtual terminal are defined in the kernel's builtin terminal emulator (
drivers/tty/vt/keyboard.c in the kernel source tree) and triggered by key combinations in the kernel's keymap (
drivers/tty/vt/defkeymap.map). Your system probably has this file (or one very similar) installed under
If you're looking to modify the switching behavior somehow, this will entail hacking on kernel code and compiling your own patched kernel.
If all you want to do is change the key combinations, you can create your own keymap and use the
loadkeys utility to install it. Start with your preferred keymap, and change the definition of the
Console_N symbols (and the related
#... keycode 59 = F1 F11 Console_13 control keycode 59 = F1 alt keycode 59 = Console_1 control alt keycode 59 = Console_1 keycode 60 = F2 F12 Console_14 control keycode 60 = F2 alt keycode 60 = Console_2 control alt keycode 60 = Console_2 #...
Note this only affects the kernel's builtin terminal emulator, meaning only the builtin virtual console is affected. X11, Wayland, and similar contexts use XKB to achieve similar functionality. In XKB, see
/usr/share/X11/xkb/compat/xfree86 for the interpreted actions,
.../xkb/types/pc for the
CTRL+ALT type used, and
.../xkb/symbols/srvr_ctrl for the F-key definitions.