However, when I press Fn-F1, it opens the Lubuntu menu, as if I'd pressed the Super_L key. It also types the letter l if I have a terminal open. My desired shortcut xscreensaver-command -lock seems to be ignored. What's going on? Why isn't my shortcut working?

I thought I could figure this out with xev, but the output of xev confuses me:

It looks like I'm getting keycode 160, which I think is XF86ScreenSaver, but it's also as if I've pressed the Super_L key and the l key. I think all this output comes from the one Fn-F1 keypress. This confuses me. How can I get Fn-F1 to lock the screen instead of opening the Lubuntu menu and typing the letter 'l'?

2 Answers
2

You can accomplish this with the xbindkeys app. Open a terminal window and type the following:

sudo apt-get install xbindkeys

Once installed you want to create two files in your home directory called:

.xbindkeysrc

This file will hold your configurations for your keybindings

.xbindkeys.noauto

This will just be a blank file but when it exists it keeps the Xserver from starting xbindkeys at boot. Although we want it to start at boot, we want to start it ourself through Startup Applications. The reason for this is the Xserver starts it to early in the boot process which sometimes causes our configs that we put in our .xbindkeysrc file not to work.

Now add the following lines to your .xbindkeysrc file

"xscreensaver-command -lock"
c:160

Save the file

Now create a little script to start xbindkeys that we'll put into our Startup Applications:

Open your favorite text editor and either copy and paste or type the following lines to it:

#!/bin/bash
sleep 10
/usr/bin/xbindkeys &

Save it in your home directory as xbstart.sh or whatever you want

Make it executable

chmod 755 xbstart.sh

Now just add that script to your Startup Applications and Reboot.

What happens is when you log in, xbindkeys gets invoked and reads your .xbindkeysrc file and runs in the background. It constantly monitors your keystrokes and when keycode 160 is pressed it will trap it before the Xserver has a chance to causing it to run xscreensaver-command -lock instead of opening your menu.

This is a good suggestion, and I'll give it a shot. If you happen to have any insight into what's currently going on when I press Fn-F1, I'm very curious. In particular, I want to know if my hardware inherently maps Fn-F1 onto XF86ScreenSaver and the Windows key and the L key, or if this is set somewhere in Linux where I can unset it.
–
AndrewMar 4 '12 at 4:13

Unlike other modifier keys such as Ctrl, Shift and AltGr, the
microcontroller inside the keyboard typically sends out a different
keycode depending on whether the Fn key is depressed. This allows the
keyboard to emulate a full-sized keyboard, so that specialised keymaps
do not need to be created; the operating system can use standard
keymaps designed for a full-sized keyboard. Because the operating
system has no notion of the Fn key, the key can not be remapped in
software, unlike all other standard keyboard keys.

This is a good, practical answer to a similar question (How can I bind locking the screen to some keyboard combination?), but not an answer to the exact question I asked (How can I get Fn-F1 to lock the screen instead of opening the Lubuntu menu and typing the letter 'l'?). This approach works for Crt-Alt-L, for example, but does not work for Fn-F1. Should I give up on binding a shortcut to Fn-F1? If so, that's ok, but I'm curious why it's so.
–
AndrewMar 4 '12 at 4:11