Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-12-16 10:26:31

New Member
Registered: 2011-12-16
Posts: 1

My scancode -> keycode -> keysym odyssey - still lost at sea

Hello folks.

This might be a bit tl;dr - it comes to a head in the penultimate par for those in a hurry smile

I'm trying to get the dead function hotkeys on my laptop keyboard working, but really I'm trying to understand how/why some work and some don't, because it doesn't make a lot of sense at the moment. I've spent a great deal of time trawling threads here, the internet, the arch wiki, tldp pages from 2002... Please excuse this brain dump; perhaps someone can fill in the blanks.

Samsung Q320 running Crunchbang/Debian Squeeze, and loving it. Trying to get acpi and fn hotkeys working properly, I have installed acpid, acpi_fakekey, acpitool, powertop, laptop-mode-tools, plus samsung-tools and samsung_backlight from So far so good - acpi pm functions work, brightness up/down keys work that didn't before, screen dims when you pull AC, some fn+F2, fn+F4, etc keys work.

I understand the keymap progression of scancode->keycode->keysym. I have used xev, xmodmap, showkey, showkey -s, and /lib/udev/keymap -i input/event0 to find codes to use with setkeycodes or insert into default keymaps but THEY ALL SHOW DIFFERENT RESULTS.

For example (normal keypress -> with fn):

$ showkey (keycodes)

Esc   1  ->  142
F2   60  ->  236
F4   62  ->  227
F5   63  ->  148
up   103    ->  225
Ins  110     ->  no result, dmesg says use setkeycodes e03a

$ showkey -s (scancodes)

Esc  0x01   ->  0xe0
F2   0x3c    ->  0xe0 0x71
F4   0x3e    ->  0xe0 0x56
F5   0x3f     ->  0xe0 0x1f
up   0xe0 0x48    ->  0xe0 0x54
Ins  0xe0 0x52     ->  no result, as above

$ sudo /lib/udev/keymap -i input/event0
(with fn pressed)
F2  -> 0x83
F4  -> 0x82
F5  -> 0x84
up     -> 0x88
Ins     -> no result

$ xev (F2, F4 and Up with and without fn:)
KeyPress event, serial 40, synthetic NO, window 0x2600001,
    state 0x0, keycode 68 (keysym 0xffbf, F2), same_screen YES,

KeyPress event, serial 40, synthetic NO, window 0x2600001,
    state 0x0, keycode 244 (keysym 0x1008ff93, XF86Battery), same_screen YES,

KeyPress event, serial 40, synthetic NO, window 0x2600001,
    state 0x0, keycode 70 (keysym 0xffc1, F4), same_screen YES,

KeyPress event, serial 40, synthetic NO, window 0x2600001,
    state 0x0, keycode 235 (keysym 0x1008ff59, XF86Display), same_screen YES,

KeyPress event, serial 40, synthetic NO, window 0x2600001,
    state 0x0, keycode 111 (keysym 0xff52, Up), same_screen YES,

KeymapNotify event, serial 40, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0 

In xev I can see that F2 and F4 (in fact, all the F keys) are bound to the right highlevel keysyms - ie XF86Battery and XF86Display - but don't trigger anything. The up cursor returns no data with fn pressed, even though with samsung_backlight etc installed the screen dims or brightens even while xev tells me nothing's happening. And none of those codes match the kernel codes - as I expected, because they're X11 keycodes and not kernel keycodes right?

$ xmodmap -pke

keycode  68 = F2 XF86_Switch_VT_2 F2 XF86_Switch_VT_2
keycode  70 = F4 XF86_Switch_VT_4 F4 XF86_Switch_VT_4
keycode  71 = F5 XF86_Switch_VT_5 F5 XF86_Switch_VT_5
keycode 238 = XF86KbdBrightnessUp NoSymbol XF86KbdBrightnessUp

But.. these are different again from xev, AND different from the kernel scancodes/keycodes.

Then I see the showkey man page that says, actually, you can't trust showkeys -s as far as you can throw it, so I reboot with the atkbd.softraw=0 kernel line. The key+fn codes are now totally different:

$ showkey -s (with and fn key pressed
Esc  ->  0xe0 0x9c
F2    ->  0xe0 0x03
F4    ->  0xe0 0x02
up      ->  0xe0 0x08
Ins     ->  0xe0 0x3a

Now I feel I'm getting somewhere. But in /lib/udev/keymaps/samsung-other and in force_release/samsung-other (which are called by the keymap rule) I have this:

0x74 prog1 # User key
0x75 www
0x78 mail
0x82 switchvideomode # Fn+F4 CRT/LCD (high keycode: "displaytoggle")
0x83 battery # Fn+F2
0x84 prog1 # Fn+F5 backlight on/off
0x86 wlan # Fn+F9
0x88 brightnessup # Fn-Up
0x89 brightnessdown # Fn-Down
0xB1 prog2 # Fn+F7 run Samsung Magic Doctor (keypressed event is generated twice)
0xB3 prog3 # Fn+F8 switch power mode (battery/dynamic/performance)
0xB4 wlan # Fn+F9 (X60P)
0xF7 f22 # Fn+F10 Touchpad on
0xF9 f23 # Fn+F10 Touchpad off

None of those keycodes bear resemblance to ANY of the codes I've managed to extract so far. What are these? Perhaps they're just wrong. So I replace them with those above from the updated showkey -s, and reboot. Everything stops working - Fkeys, brightness keys, everything.

$ cat /sys/devices/platform/i8042/serio0/force_release

4 cat /sys/devices/platform/i8042/serio0/force_release

Put back these mystery numbers and everything reverts to how it was. So it seems there must be... ANOTHER set of codes, which this force_release and keymap file is using? Really? So I have six different sets of codes, none of which seem to marry up. And I haven't even mentioned the acpi keycodes I can see with acpi_listen.

So I'm asking; if there are only supposed to be three levels (scan->key->X11) then why do I have six sets? When I use setkeycodes, which do I use? If I edit a keymap, which am I supposed to use? What is the force_release usage, and where do these numbers come from? Because they don't seem to refer to any of the other numbers I've found. In fact, how can there be numbers like 369-370, I thought it only goes to 256? And why do certain things work on a high level (openbox will mute/vol up/vol down for example), but I can't get the same functionality to work on a lower, kernel/udev level? I'm trying to get Fn+Insert to eject the CD, for example, and though "ejectcd" is on the list of symbols:, I can't get a keymap file to accept it.

I'm really lost, so if I'm just barking up the wrong tree could someone just put me out of my misery.

Apologies for length. Perhaps some other Samsung users could report their experiences?


Last edited by astarix (2011-12-16 10:31:25)


Be excellent to each other!

#2 2011-12-16 11:05:10

From: inside Ed
Registered: 2011-07-25
Posts: 4,749

Re: My scancode -> keycode -> keysym odyssey - still lost at sea

Ugh, I think you over-thought this somewhat. As far as I can understand, the samsung-tools and samsung-other package remapped some of your keys to launch Samsung specific programs (like this Samsung Magic Doctor). Since you downloaded them from a Samsung forum, I those modules are not in the mainline kernel tree, which is why you're getting some confusion.

In general, the kernel should pick up on ACPI keys and handle them separately from X. As I see it, you don't have problems with those, right? Multimedia keys (XF86AudioPlay/Stop/Next/Whatever) are handled differently. That's because you can't know befiorehand which audio system and subsystem the user is gonna go with (OSS, ALSA, Pulse, JACK), so they're usually not mapped. The Gnome or KDE desktop environment on some distros does map them, but Debian is very generic.

Generally, you'd find the names of the keys with xev, and apply them directly to your window manager. In Openbox, it would be rc.xml, in other WMs there are other config files or their GUI representations. I don't see much of a point in mapping multimedia keys outside of X, because you're not very likely to use them. udev rules could probably be written though.

Your keymap selection shouldn't mattter, the keymap deals with letters and signs, not special keys. Remapping some keys, like have "K" spell "&" is done with xmonadp. I'm running this in my startup:

xmodmap -e "keysym 0x2b = 0x2f" &


Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: zapp

Debian Logo