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.

RobertL
  • 6,690
  • 1
  • 19
  • 38
Jes
  • 461
  • 1
  • 5
  • 10
  • 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 '12 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. – Volker Siegel Jul 23 '14 at 09:49

5 Answers5

30

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.

RobertL
  • 6,690
  • 1
  • 19
  • 38
  • 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 '15 at 08:48
  • I have tried several ways and this one was the only that works in Lubuntu 16.04, it works when I'm logged in. Do you know how to get it to work in lxdm's greeter screen? (in ubuntu with lightdm works). – J.Serra Apr 15 '16 at 14:01
  • 1
    It works on Linux Mint 18. Thank you. – Hoang Tran Jul 17 '17 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 '17 at 18:34
  • Works like a charm on Linux 18.3, many thanks. – gilbertohasnofb Jan 16 '18 at 11:13
  • Works in Kubuntu 1804, cheers. – Jes May 25 '18 at 21:57
  • 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. – Martin Dorey Jun 20 '18 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! – Per Lundberg Jul 08 '19 at 13:32
  • I only tested the disabling so far and it works great, thanks for proper Linux-style solution. – Rostislav Matl Oct 07 '20 at 14:24
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.)

Julie Pelletier
  • 7,562
  • 1
  • 20
  • 43
Sam Morris
  • 992
  • 6
  • 10
  • This does not forward the combination to the window, X still catches it. – Jes Mar 14 '12 at 19:25
  • I did some Googling and found you need to add something else to the config file. Let me know if it works. – Sam Morris Mar 15 '12 at 11:49
  • 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 '12 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 '13 at 00: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. – Devs love ZenUML May 17 '16 at 07:43
  • 1
    Just to confirm this works on FreeBSD 11 too. – gsl Jul 07 '17 at 17:25
  • @XiaoPeng You can switch the entire keymap to 'Default' and then you'll get all the old shortcuts. – Jes Jul 13 '17 at 11:13
  • How about for Wayland? How would you disable it there? – Omnifarious Sep 17 '18 at 15:10
  • I think it would be up to individual compositors (e.g., weston, gnome-shell, plasma) to provide a mechanism to disable VT switching. – Sam Morris Nov 15 '18 at 11:13
5

You can disable this by going to System settings -> keyboard layout -> option. 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!!!.

manatwork
  • 30,549
  • 7
  • 101
  • 91
rezamda
  • 59
  • 1
  • 1
  • You are right Ubuntu does not catch it, but I suspect that the X server does. – Jes Mar 26 '13 at 14:45
  • 4
    Yay! Found out that by default in Ubuntu IDEA handles Ctrl + Alt + **7** instead of **F7**! – o_nix Oct 30 '13 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.

vort2020
  • 21
  • 1
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 "['']"
Eduard Wirch
  • 111
  • 2