Home > Linux > Samsung Fn hotkeys and Arch Linux

Samsung Fn hotkeys and Arch Linux

July 14th, 2010

I’ve got a new Samsung R530 laptop. The first thing I did when I got it was to install Arch Linux (my Linux distro du jour). I nearly broke everything when I installed Grub in the Windows boot partition (I think Grub and NTLDR were fighting), but it all turned out well in the end.

I really like developing in Linux – it really is the perfect development environment. It’s just a pain that everything doesn’t work out of the box. The thing I’ve had the most trouble with is the keyboard ‘Fn’ hotkeys. By this I mean combinations like Fn + Up (brightness up), Fn + F4 (switch display) etc. I’m going to walk through the steps I took to get these keys working in Arch Linux in the hope that someone in the same situation as me may be saved the hours of faffing I’ve had to do.

First, I tried finding out the keycodes using xev and acpi_listen, as suggested by this Super User question. xev showed the volume hotkeys working (which were doing their job anyway), but neither showed anything for the brightness keys. I asked the Arch Linux forum for help and was directed to the Extra Keyboard Keys Arch Wiki page. There I learnt my first lesson:

A scancode is the lowest identification number for a key. If a key doesn’t have a scancode then we can’t do anything because it means that the kernel doesn’t see it.

A keycode is the second level of identification for a key, a keycode corresponds to a function.

A symbol is the third level of identification for a key, it is the way Xorg refers to keys.

I used showkey to find out if the problem keys had keycodes, and discovered that they didn’t. If a key doesn’t have a keycode, it can still have a scancode. If it doesn’t have a scancode then the kernel just doesn’t see it, and you’re screwed. To find out if a key has a scancode, run dmesg | tail -5 after pressing one of the keys. This should tell you what the scancode is, and tell you how to map the scancode to a keycode.

So, at this stage I was able to discover the scancodes of all the non-functioning hotkeys. I made a list a bit like this:

  • Fn + F2: Show battery – e003
  • Fn + F4: Switch display – e002
  • Fn + F5: Backlight on/off – e004
  • etc…

The next step was to follow the instructions in Map scancodes to keycodes. This told me to look in /lib/udev/keymaps. I found samsung-other in there, which contained the following:

0x82 switchvideomode # Fn+F4 CRT/LCD (high keycode: "displaytoggle")
0x83 battery # Fn+F2
0x84 prog1 # Fn+F5 backlight on/off

In fact, every item in samsung-other matched the keycodes I’d found. Great! The next step is to tell udev to use these keycodes. To do this, make a new file in /etc/udev/rules.d/ called 10-local.rules (as suggested in Writing udev rules), and write:

SUBSYSTEM=="input", ATTRS{name}=="AT Translated Set 2 keyboard", RUN+="keymap $name samsung-other"

Replace samsung-other with your keymap if you’re using a different one. Reboot, then run showkey and see if the keys have keycodes (they should do now). If not, you’ll need to look to Map scancodes to keycodes for advice.

At this point, I’ve got working keycodes, but it seems like X is receiving constant key presses when I press one of them, and it’s causing the computer to crash. I don’t actually have a solution to this at the moment. I thought I’d post this in case my working helps anyone else with a similar problem. Maybe it’ll work for you!

Categories: Linux Tags:
  1. 3cHeLoN
    July 25th, 2010 at 16:38 | #1

    I have found a solution for this. You need the force-release patch. I added a udev rule in /etc/udev/rules.d/95-keyboard-force-release.rules I used the 95 so it loads after the keycode is set, which I do in 10-locale.rules. The rule I added was:

    +ENV{DMI_VENDOR}=="[sS][aA][mM][sS][uU][nN][gG]*", ATTR{[dmi/id]product_name}=="*R522*", RUN+="keyboard-force-release.sh $devpath samsung-other"

    where R522 is my model, substitute your own. Now after a reboot, when you press the brightness keys it detects a press and immediately a release, which is good enough.

    To control the brightness I had to make a perl script, because xbacklight didn’t work for me. The script is only valid for gnome, let me know if you want it.

  2. 3cHeLoN
    July 25th, 2010 at 16:40 | #2

    the R522 part needs an astrix on both sides, but it doesn’t show up in my previous post

  3. July 30th, 2010 at 09:11 | #3

    @3cHeLoN

    FTFY :)

    Anyway, thanks for this – when I have time I’ll try it out.

Comments are closed.