When I run emacs24 on the console the Fn key on both my Lenovo laptops sets the selection mark (in the same way as C-SPC). That's pretty crazy behavior as I need the Fn key to change screen brightness, sound volume etc.

How do I unbind the Fn key so it doesn't do anything in emacs?


If I press C-h k Fn in emacs I get exactly the same output as if pressing C-h k C-SPC:

C-@ runs the command set-mark-command, which is an interactive compiledLisp function.
It is bound to C-@, C-SPC.

(set-mark-command ARG)

If I run acpi_listen and press the Fn key I get the output:


This is the exact same output I get from acpi_listen if I press C-SPC or C-@ (Ctrl+AltGr+2). That is: they're all registered as the same acpi event.

Discovering that, I've tried to unsetC-@. The only way I've got it working is with this:

 (global-set-key (kbd "\C-@") 'ignore)

And this:

 (global-set-key (kbd "\^@") 'ignore)

In both instances that prevents C-SPC from working too(!) I've tried re-setting C-SPC with:

(global-set-key (kbd "C-SPC") 'set-mark-command)

But that doesn't take effect.

After this I can refine my question to this:

Giving that C-SPC and Fn are registered as the same acpi event can I make emacs distinguish between them?

(Note that this is only a problem in the console. Emacs doesn't pick up the Fn key on my X machine ...)

  • Run the command xev from a terminal and press the Fn key. A paragraph beginning with KeyPress event, serial … will appear in the terminal. Copy-paste it here. Note that the blog post you read is overgeneralizing: on most laptops, the Fn key is interpreted by the BIOS, it doesn't send a keyboard event at all. We need to determine what keyboard event the key sends on your computer. Mar 22 '14 at 23:25
  • xev gives me the output: xev: unable to open display ''. Guess the reason for this is simply that I don't have the X org server installed - this is a console machine meant for solely for running emacs in the console. Normally the Fn key combos don't get registered by xev at all because as you say they're acpi events interpreted by the BIOS. That's why it's so strange that emacs picks it up. The output of pressing Fn with acpi_listen is simply: ^@. Only if I press it combination with the arrow keys or F1-11 do I get more output. Mar 23 '14 at 11:19
  • Ah, on the console? You should have said, that's unusual. Which unix variant? On Linux, run showkey. Mar 23 '14 at 13:49
  • I actually did say that I'm running emacs on the console - even in the title. I'm running Debian testing (netinstall).showkey gives me: Couldnt get a file descriptor referring to the console... Mar 23 '14 at 14:31
  • Oh, sorry, indeed you did. Run showkey from a console, as root. Mar 23 '14 at 14:50

This solution using dumpkeys, loadkeys and showkey is likely to work in other instances of function keys getting interpreted in unexpected ways by programs running in the Linux Virtual Console.

Find the keycode of the key or key combo causing trouble by running:

 $ sudo showkey

... and hitting the key. In my instance hitting Fn gave the output 143.

To stop Fn from being interpreted as anything by programs in the console, add this /etc/rc.local:

(dumpkeys | grep keymaps; echo "keycode 143 =") | loadkeys

143 should of course be replaced by the keycode of the relevant key in question. I also had a problem with Fn+LeftArrow (meant for volume down) outputting a tilde, so I got the code for that combo as well, and threw in another line for that in /etc/rc.local.

Note that this doesn't prevent the normal behavior of the Fn functions (changing volume, brightness etc.) it only prevents function keys from being interpreted as anything by programs like emacs.

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.