[version Dec. 21 2008 2pm]

Note: this writeup is only for Ubuntu 8.10, which I’m using at the moment. If you know Python it can be adapted to other distributions, it’s a matter of formatting the output style of amixer on your system. Even without changes however, most of these key fixes should work on Fedora 10.

1) The Problem

Normally setting up multimedia and other special keys in Linux involves telling the kernel the keys’ correct keycodes using setkeycodes and perhaps mapping them to X Server behaviors via xmodmap. Unfortunately there is some kind of glitch in Fedora which causes most of the Fn-* keys to loop infinitely. A plausible explanation for this is that only key_press events are being sent to X and not key_release events, but the reason isn’t important here.  This problem apparently does not affect other distributions.

In this writeup I give a method to make all (okay, most) of the Fn-* keys work via Ctrl-* instead. Below is a table of the special keys and their current support. After that is a guide for getting Ctrl-* support working on your system.

2) Chart of Special Keys

“Fn Support” indicates status of Fn-* keys. I will not show the hacks here to get Fn-F2 and Fn-F7 working, because they cause problems behind the scenes, wasting CPU cycles indefinitely once pressed.

“Ctrl Support” indicates whether equivalent functionality can be achieved with Ctrl-* post-writeup. The goal of course is to be able to do everything with Ctrl-* and forget about the Fn key, but that has not been achieved yet. For now, both will have to be used.

Base key Fn Support Ctrl support Behavior
Esc Yes Suspend to RAM
F2 Partial (with hack) Yes Display Battery Status
F3 Yes Insert Euro Symbol
F4 Yes ** Toggle Displays
F5 Yes Toggle Backlight
F6 Yes Yes Toggle Sound
F7 Partial (with hack) Yes Launch Default Mail Client
F8 *** CPU Mode
F9 **** Toggle Wireless Card
F10 Yes Toggle Touchpad
F11 Yes Yes Num Lock
F12 ? scroll lock ?
PgUp Yes Home
PgDown Yes End
Up Yes Increase Brightness
Down Yes Decrease Brightness
Left Yes Yes Decrease Volume
Right Yes Yes Increase Volume
Windows Yes Yes Whatever You Want

3) Ctrl-* Writeup

Windows Logo Key

First something easy. The default Linux mapping of the Windows Logo key (Meta) isn’t something most desktop users will find very useful. Type gnome-keybinding-properties at the Terminal and bind the key to something of your choice. I have it launch Terminal.

Other Keys

First install the packages we’re going to need:

sudo apt-get update
sudo apt-get install xbacklight
sudo apt-get install xosd-bin
sudo apt-get install xbindkeys
sudo apt-get install python-virtkey
sudo apt-get install compizconfig-settings-manager

Place my Python script (available here or here) in /usr/bin to guarantee it’s in your path.
Also place my C program (available here or here) in /usr/bin (source available here or here for those who are curious).
Make the files executable with:

chmod +x /usr/bin/nc10_keys.py
chmod +x /usr/bin/battery_xosd

Place my xbindkeys configuration file (available here or here) in your home directory and rename it .xbindkeysrc (including the initial “.”).

Configure the xbindkeys command to be executed at system startup through System -> Preferences -> Personal -> Sessions.

Now start xbindkeys by typing xbindkeys in Terminal and you’re ready to go.


** Ctrl-F4 currently launches CompizConfig Settings Manager, you may want to change this to launch a XRandR multiple screens GUI or something else you have installed.

*** F8 (toggle CPU speed) is not supported by the kernel. I have mapped Ctrl-F8 to launch Pidgin instead, since the running guy looks like the AIM logo.

**** F9 (toggle wireless card) is not a feature supported by the current driver. I have mapped it to launch the default web browser instead.

If you’d like to help me bind the rest of the functions to Ctrl, reading the python script and its comments is a good place to start.

15 Comments

  1. [Ed.: please note that many of the comments below are in reference to a kernel patch available elsewhere, not the writeup on this page @carneades]

    There is a patch available at http://bugzilla.kernel.org/show_bug.cgi?id=12021
    The Patch needs to be slightly modified to make all keys work.
    Together with this patch to hal-info no more hacks are required.
    http://cgit.freedesktop.org/hal-info/diff/?id=fa25c3520610d2b096b3d7e95edd45acf37c3561

  2. Hello is difficult apply the patch,I’m a xp user and in ubuntu I’m not an expert
    thank you

  3. Hi Thoemy
    I applied the kernel patch to a 2.6.27.9 generic kernel and rebuilt. Now, I have the brightness keys working, plus Mouse on / off (but no OSD) and battery key.

    There is still a problem with the brightness key, though. If you turn brighness all the way down to black using fn-down, the fn-up / fn-down keys no longer respond, and I have to use the the Ctrl-up (workaround) key to restore brightness. Subsequently neither fn-up or fn-down respond.

    Now for the HAL patch, I cannot build the hal-info code, there is an error caused by not having PolicyKit installed. Problem is, it is installed, I can see it in Apt. Any advice here?

  4. Hi Jon,

    the brightness keys work fine for me. Even if I turn the brightness down to zero. I don’t know what could be wrong on your side. Did you grab the second patch? The first one does not include the scancodes for the brightness keys. I’m also using Fedora 10.

    You don’t have to rebuild hal-info. It just contains a couple of config files that are read if hal starts. You can copy 30-keymap-misc.fdi from the repository and overwrite the file in /usr/share/hal/fdi/information/10freedesktop or create your own one in /etc/hal/fdi/information

  5. Ah-ha! OK, I’ll give it a try. As to scancodes, I set those in the samsung.hk file.

  6. Thoemy, can you please post your samsung.hk file? It’s in /usr/share/hotkey-setup. I have applied the hal patch but I still get the same issue. It happens when you press and hold the bright-down key (fn-down) – it’ll go to dark, but then the keys stop responding. Can you confirm that your installation doesn’t behave like this please?
    Thanks
    JonB

  7. where is atkbd.c? in my system is not present (ubuntu 8.10) and is impossible tthe patch

  8. hotkey-setup seems to be Ubuntu specific. If you patched HAL you wont need to set the scancodes in the samsung.hk file. To see if HAL picked up your changes you can check if the output of “lshal | grep keymap.data” looks similar to this:
    input.keymap.data = {‘e008:brightnessup’, ‘e009:brightnessdown’, ‘e003:battery’, ‘e002:switchvideomode’, ‘e004:displaytoggle’, ‘e031:prog1′, ‘e033:prog2′, ‘e006:wlan’, ‘e079:f22′, ‘e077:f22′} (string list)

    And yes, I can confirm that the brightness keys are still working fine after I pressed Fn+down till the screen was black.

  9. never000,

    you need to download the kernel sources and patch the kernel. After that you have to build your own kernel. I’m sure that there are guides for Ubuntu out there.

  10. thank you

  11. lshal | grep keymap.data output is nil. So I guess it’s not in use on Ubuntu :(

  12. I’m sorry, but I can’t help you any further for the moment. I see no reason why it should not work on Ubuntu.

    I have this file http://dl.getdropbox.com/u/175389/30-keymap-samsung.fdi in /etc/hal/fdi/information/ and not the updated one in hal-info although the result should be the same. The lshal output will probably be different because the fdi file in hal-info maps some more scancodes for which there are no keys on the NC10.

  13. OK, thanks mate. I have to note here that the recompiled kernel killed my wifi driver! D’oh… back to the drawing board…

  14. Jon,

    You killed the wlan while compiling your kernel. Not a problem with the kernel, but the private rolling it ;)


Post a Comment

*
*