21

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.

  • 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 9:49
10

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.)

  • This does not forward the combination to the window, X still catches it. – Jes Mar 14 '12 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 '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 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. – Xiao Peng - ZenUML.com May 17 '16 at 7:43
  • 1
    Just to confirm this works on FreeBSD 11 too. – gsl Jul 7 '17 at 17:25
15

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.

  • 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 8: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
  • 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 8 at 13:32
1

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!!!.

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

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.

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

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.