27

I have an application that binds CTRL+ALT+F7, but my linux machine seems to catch the keystroke.

Is there a way to rebind/disable this key? A recompile of the kernel is an acceptable answer.

The distributions in question are Fedora 16 and Ubuntu 11.10.

2
  • I don't have any specific advice, but I think, as CTRL+ALT+Fn is bound only under the X-Windows System, that the kernel won't be related to it in any way, and that you will probably be luckier trying to tweak the X11 configuration.
    – njsg
    Mar 14, 2012 at 16:48
  • @njsg You can use the same keys to switch from X11 to a vt, and to switch back (also between vt's) - so they must be bound just the same on a vt. Jul 23, 2014 at 9:49

5 Answers 5

29

The following invocation of the X11 setxkbmap command disables Ctrl-Alt-Fn console/virtual terminal switching:

setxkbmap -option srvrkeys:none

To return to the previous behavior of the ctrl-alt-Fn keys, and also remove all other options, such as caps:ctrl_modifier:

setxkbmap -option ''

To print the current settings invoke setxkbmap -print.

To invoke per user, put the command in the ~/.xinitrc file.

To invoke when an Xsession starts, create a file in

/etc/X11/Xsession.d

such as

/etc/X11/Xsession.d/65srvrkeys-none

containing the above setxkbmap command, and make it executable with sudo chmod +x /etc/X11/Xsession.d/65srvrkeys-none.

For more information type man setxkbmap at your shell prompt or see the Xorg setxkbmap man page.

I tested this with KDE on Ubuntu 14.04 LTS (Trusty). These settings are also available in System Settings > Input Devices > Keyboard > Advanced. If you change srvrkeys in the GUI Settings, it shows up immediately in setxkbmap and vice versa.

I prefer to modify the X window system via the X11 command line interfaces. If that does not work, then I attempt the desktop environment. As a last resort I would modify system configuration files. Implementations and file formats change, but command line interfaces live almost forever in the Unix/Linux tradition.

9
  • Thanks, @RobertL. My hopes were high, but no, this doesn't seem to have any effect on my Debian jessie and Ubuntu 14.04 installations. Ctrl-Alt-F7 and Ctrl-Alt-F8 still switch back and forth to and from a virtual terminal. I also don't have that menu entry System Settings > Input Devices > ... Perhaps that's a KDE thing? I'm using GNOME or whatever the Ubuntu default is.
    – glts
    Nov 13, 2015 at 8:48
  • 1
    It works on Linux Mint 18. Thank you.
    – Hoang Tran
    Jul 17, 2017 at 12:01
  • 1
    It works for me on Debian 8 (Jessie). NOTE: I only tested the command line setxkbmap -option srvrkeys:none. I put the entry in a file in /etc/X11/Xsession.d/65srvrkeys-none. And while I haven't logged out and back in yet, I presume it will work just fine.
    – MikeyE
    Sep 27, 2017 at 18:34
  • 1
    Why would I want to restart X, per @Sam Morris's accepted answer, when I could stop it from stealing the keypress from my vmware vSphere 6.5 web console with one simple, instant, easily undone command? RobertL, you sir, are a gentleman and a scholar. All the ghits saying Ctrl-Alt-Space, release Space, F1, that no longer works with webconsole. All the ones saying "host key", I don't know what that refers to. All the ones referring to VMRC, I don't have a my.vmware.com account to download that from. Jun 20, 2018 at 17:03
  • 1
    Worked fine for me on Debian Buster; like @MikeyE I haven't logged out yet (and will probably not do so in a couple of weeks/months ;-) but the setxkbmap approach did the trick. Much appreciated! Jul 8, 2019 at 13:32
12

Place this in your /etc/X11/xorg.conf file to disable VT switching with Ctrl+Alt+Fn:

Section "ServerFlags"
    Option "DontVTSwitch" "on"
EndSection

You will also need the following to cause events to be passed through to clients connected to the display:

Section "InputClass"
    Identifier "keyboard defaults"
    MatchIsKeyboard "on"
    Option "XKbOptions" "srvrkeys:none"
EndSection

(That last bit is untested, refer to its source.)

9
  • This does not forward the combination to the window, X still catches it.
    – Jes
    Mar 14, 2012 at 19:25
  • 2
    After a few months of having to run Windows I have finally tested this on Lubuntu 12.04, where the IntelliJ IDEA window still does not catch the keystroke.
    – Jes
    Aug 14, 2012 at 20:52
  • 2
    Using the two settings was both required for me, and worked for me. (on centos). ctrl-alt-f7 is now showing the usages inline in intellij :).
    – Rob Dawson
    Apr 15, 2013 at 0:11
  • 3
    If you are using Intellij and want to use CTL+ALT+F7 for "Show usage", on Lubuntu 15.04, the default shortcut is acutally CTL+ALT+7. You would need to change it back to CTL+ALT+F7 if you want to keep consistent with other OSes. May 17, 2016 at 7:43
  • 1
    Just to confirm this works on FreeBSD 11 too.
    – gsl
    Jul 7, 2017 at 17:25
5

You can disable this by going to Tweaks -> Keyboard & Mouse -> Additional Layout Options. under miscellaneous compatibility options check "special keys Ctrl+Alt+<key> handled in server".

I checked this and Ubuntu does not catch any combination of Ctrl+Alt+... . but still idea does not catch Ctrl+Alt+F7 and the problem still exits!!!.

2
  • You are right Ubuntu does not catch it, but I suspect that the X server does.
    – Jes
    Mar 26, 2013 at 14:45
  • 4
    Yay! Found out that by default in Ubuntu IDEA handles Ctrl + Alt + 7 instead of F7!
    – o_nix
    Oct 30, 2013 at 12:11
2

In Ubuntu 18.04 you need to create the following file:

/usr/share/X11/xorg.conf.d/65-setxkbmap

with this content:

Section "ServerFlags"
    Option "DontVTSwitch" "on"
EndSection

Section "InputClass"
    Identifier "keyboard defaults"
    MatchIsKeyboard "on"
    Option "XKbOptions" "srvrkeys:none"
EndSection

then reboot your system.

1
  • Except for the filename, this has been suggested in the accepted answer.
    – RalfFriedl
    May 11, 2019 at 21:16
0

Solution for Gnome Wayland: You can unset the keybindings for virtual terminal switching by setting these dconf properties:

dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-1 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-2 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-3 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-4 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-5 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-6 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-7 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-8 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-9 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-10 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-11 "['']"
dconf write /org/gnome/mutter/wayland/keybindings/switch-to-session-12 "['']"

You must log in to answer this question.

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