4

I'm using a Toshiba r835 with Lubuntu. After a clean install, pressing the power button while the machine is on does nothing. I fixed the power button by following this advice:

I added these lines to ~/.config/openbox/lubuntu-rc.xml

<keybind key="XF86PowerOff">
<action name="Execute">
<command>lubuntu-logout</command>
</action>
</keybind>

This makes sense to me.

I want to map several other keys to similar shortcuts. For example, when I press Fn-F1, I want to lock the screen. I imagine I would add something like

<keybind key="XF86ScreenSaver">
<action name="Execute">
<command>xscreensaver-command -lock</command>
</action>
</keybind>

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:

FocusOut event, serial 41, synthetic NO, window 0x2000001,
mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 41, synthetic NO, window 0x2000001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 41, synthetic NO, window 0x0,
    keys:  0   0   0   0   0   64  0   0   0   0   0   0   0   0   0   0   
           32  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

MappingNotify event, serial 41, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 41, synthetic NO, window 0x2000001,
    root 0xae, subw 0x0, time 16525549, (289,-138), root:(341,155),
    state 0x40, keycode 160 (keysym 0x1008ff2d, XF86ScreenSaver), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 41, synthetic NO, window 0x2000001,
    root 0xae, subw 0x0, time 16525550, (289,-138), root:(341,155),
    state 0x40, keycode 160 (keysym 0x1008ff2d, XF86ScreenSaver), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

MappingNotify event, serial 42, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyRelease event, serial 42, synthetic NO, window 0x2000001,
    root 0xae, subw 0x0, time 16525639, (289,-138), root:(341,155),
    state 0x40, keycode 46 (keysym 0x6c, l), same_screen YES,
    XLookupString gives 1 bytes: (6c) "l"
    XFilterEvent returns: False

KeyRelease event, serial 43, synthetic NO, window 0x2000001,
    root 0xae, subw 0x0, time 16525646, (289,-138), root:(341,155),
    state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

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'?

Andrew
  • 253

2 Answers2

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. – Andrew Mar 04 '12 at 04:13
2

I added this

<keybind key="C-A-L">
  <action name="Execute">
    <command>xscreensaver-command -lock</command>
  </action>
</keybind>

so when I do Crt+Alt+L my screebscaver start... like @fossfreedom show me

so I supouse you have to do something similar

<keybind key="C-F1">
  <action name="Execute">
    <command>xscreensaver-command -lock</command>
  </action>
</keybind>

but first check if that keybind is not already used.

... About the fn option that you wanted: I will quote wikipedia.

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.

maniat1k
  • 8,130
  • 1
    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. – Andrew Mar 04 '12 at 04:11
  • 1
    mmm my bad but I don't think you can map fn key in particular: will edit my answer. – maniat1k Mar 06 '12 at 09:04
  • Ah, interesting! Good link from WP, I didn't know about that. – Andrew Mar 06 '12 at 13:50