You are not logged in.

#1 2008-02-09 19:31:35

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Scancode/Keycode guru in the house? I'm at my wits end.

After doing a fresh Arch installation this week, I can't get my notebook's function keys working quite like they did before.  For starters, I noticed that the kernel has actually assigned a keycode to ALL of them, which is unusual because typically I had to set a few manually. I should be happy about this, except that the assigned keycodes don't work.

When monitored with xev, these particular keys seem to get "stuck" on. That is to say that when I press them once, xev's output scrolls off the screen continuously until I press Esc. From there after, they no longer produce ANY response until I restart X. Furthermore, when I associate these keys to a program with xbindkeys, it will open 40+ instances of the application and lock up my system.

To get around this, I have tried to manually assign the scancodes to a different keycode to see if that helps, but the kernel (and X) keycode doesn't change even if I explicitly set it with setkeycodes.

I've spent about 4 hours on this now and I'm ready to pull out my hair.  Has anybody else seen this sort of behaviour? Below are all the bits I think could possibly be relative.  Any help would be greatly appreciated.

 $ uname -a
Linux dublin 2.6.23-ARCH #1 SMP PREEMPT Tue Jan 15 06:34:36 UTC 2008 i686 Genuine Intel(R) CPU T2500 @ 2.00GHz GenuineIntel GNU/Linux

showkey/xev output:

scancode  keycode  X-keycode
x25         205       165
x72         237       242
x71         236       241
x7d         162       253

dumpkeys output (unassigned codes):

keycode 120 =
keycode 121 =
keycode 122 =
keycode 123 =
keycode 124 =
keycode 125 =
keycode 126 =
keycode 127 =

/etc/rc.conf:

LOCALE="en_CA.utf8"
KEYMAP="us"
CONSOLEFONT=

/etc/rc.local:

setkeycodes e025 121  # fn hibernate
setkeycodes e072 122  # fn wifi
setkeycodes e071 123  # fn battery
setkeycodes e07d 124  # fn eject

As I said, even with these setkeycodes commands, the showkey command still reports the old keycodes (205 instead of 121, 237 instead of 122, etc., etc.)

/etc/X11/xorg.conf:

Section "InputDevice"
    Identifier  "Dell Keyboard"
    Driver      "keyboard"
    Option        "XkbRules" "xorg"
    Option        "XkbModel" "pc105"
    Option        "XkbLayout" "us"
    Option        "XkbVariant" ""
    Option        "Autorepeat" "400 40"        # Repeat pause and speed
EndSection

Last edited by thayer (2008-02-09 19:33:51)


thayer williams ~ cinderwick.ca

Offline

#2 2008-02-10 17:29:35

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

Nobody? Perhaps I should ask a more general question...

Has anyone experienced similar behaviour when using a function key in X, where xev will scroll the output indefinitely until Esc is pressed?


thayer williams ~ cinderwick.ca

Offline

#3 2008-02-11 05:40:01

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: Scancode/Keycode guru in the house? I'm at my wits end.

thayer wrote:

Nobody? Perhaps I should ask a more general question...

Has anyone experienced similar behaviour when using a function key in X, where xev will scroll the output indefinitely until Esc is pressed?

Yes, I have and continue to experience this. It seems that no matter what I do I cannot get certain keys to work at all in X. Using setkeycode works fine and showkey shows the correct key codes, but I see the behavior you mention in X. I've got a Dell Inspiron 9300, and here's a list of what works and what doesn't.

Fn+Esc (Standby)  - works, generates an ACPI event, no config necessary
Fn+F1 (Hibernate) - works, mapped with setkeycodes and Xmodmap, trapped with xbindkeys
Fn+F2 (Wifi)      - works, turns wifi card on and off, weird xev behavior
Fn+F3 (Battery)   - ?, doesn't seem to do anything, weird xev behavior
Fn+F8 (CRT/LCD)   - works, mapped with setkeycode, X picks up this key automatically
Fn+F10 (Eject)    - works, mapped with setkeycodes and xmodmap, trapped with xbindkeys
Fn+PageUp/PageDown/End - work for volume, no config necessary
Fn+Up/Down        - work to adjust LCD brightness, no config necessary
Fn keypad         - works

My setup is pretty much like yours, but here it is, just in case.

#!/bin/bash
#
# /etc/rc.local: Local multi-user startup script.
#

# Map special keys on Dell keyboard
setkeycodes e00a 123  # Fn+F1 (Hibernate)
setkeycodes e008 121  # Fn+F2 (Wifi)
setkeycodes e007 120  # Fn+F3 (Battery)
setkeycodes e00b 124  # Fn+F8 (CRT/LCD)
setkeycodes e009 122  # Fn+F10 (Eject)
! ~/.Xmodmap

! Make Caps_Lock a modifier key
clear Lock
add mod4 = Caps_Lock

! Make left Windows key be modifier, get rid of spurious "Hyper_L"
remove mod4 = Super_L
remove mod4 = Hyper_L
add mod3 = Super_L

! Multimedia buttons
keycode 160 = XF86AudioMute
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
keycode 162 = XF86AudioPlay
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 164 = XF86AudioStop

! Fn keys
keycode 209 = XF86Sleep ! Fn+F1 (Hibernate)
keycode 210 = XF86Eject ! Fn+F10 (Eject)
# For the benefit of emacs users: -*- shell-script -*-
###########################
# xbindkeys configuration #
###########################

"/usr/local/bin/toggle_sound"
  XF86AudioMute

"/usr/local/bin/volume_down"
  XF86AudioLowerVolume

"/usr/local/bin/volume_up"
  XF86AudioRaiseVolume

"/usr/local/bin/hibernate"
  XF86Sleep

"/usr/bin/eject"
  XF86Eject

"/usr/bin/mocp -G"
  XF86AudioPlay

"/usr/bin/mocp -r"
  XF86AudioPrev
  
"/usr/bin/mocp -f"
  XF86AudioNext

"/usr/bin/mocp -s"
  XF86AudioStop

"/usr/bin/scrot &"
  Print

"/usr/bin/scrot -b -s &"
  Alt + Print
# xorg.conf
...

Section "InputDevice"
    Identifier  "Keyboard0"
    Driver      "keyboard"
    Option        "CoreKeyboard"
    Option        "XkbRules" "xorg"
    Option        "XkbModel" "pc105"
    Option        "XkbLayout" "us,latam,br"
    Option        "XkbOptions" "grp:shifts_toggle"
EndSection
...

This is the best I've ever been able to get things working. Perhaps it has something to do with the keyboard model I'm using. I don't know, as I've not really tried changing this systematically. Anyway, I hope this helps a bit. What problems did you have exactly and with which keys?

Regards,
j

Offline

#4 2008-02-11 20:34:45

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

Thanks jbromley, it's good to know I'm not the only one experiencing this weird behaviour.  I've googled extensively and it seems that scancodes/keycodes are just too esoteric for most people to bother with.

My current issues are just that the Hiberbate and Eject keys aren't working no matter what I do.  I don't mind so much about the wifi acting weird with xev since it does at least toggle the wifi card as it should.  I'd like to take advantage of the battery shortcut though as I've been working on some power-management scripts and it would be the most appropriate key function for them.

Something else I've noticed is that the scancodes don't even seem to be the same any more.  For example, under my previous installation, the Hibernation key was e00a (same as yours), but now showkey says it's 0xe0 0x25 with a keycode of 205.  I wouldn't think the scancode values would change between software installations on the same hardware.  No amount of using setkeycodes has allowed me to change the keycode from 205, which is just weird.


thayer williams ~ cinderwick.ca

Offline

#5 2008-02-11 22:01:43

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: Scancode/Keycode guru in the house? I'm at my wits end.

I believe these problems are fairly common for Dell laptops, as I've seen references to the same in a number of places. If you take a look at the Dell section of Linux on Laptops you'll see at least one example of this.

Regarding the scan codes changing, that is a kernel issue. What is happening is that since kernel 2.6 when you ask for scancodes with showkey, what you get are the keycodes "translated back" to the scancodes. The problem is these scancodes are not always the real codes, as you have seen. I believe this is called soft raw translation in the kernel. To see the real scancodes (e00x for the keys we're talking about) add the parameter atkbd.softraw=0 to your kernel boot line. With this boot parameter you will see the real scancodes with showkey. It is not necessary to always boot with this parameter, just when you want to see real scancodes.

Now, regarding your problem -- in light of the soft raw issue mentioned above what your are saying makes sense. The showkey program is telling you the scan code is e025, and you map this with setkeycodes, however, it seems likely that the reported scan code is not correct and so you can't seem to change the keycode. I would suggest booting with the atkbd.softraw=0 option and then checking the scancodes with showkey -s. If you see a discrepancy there, that would be the first thing to fix. One other thing, are you using any special console map? (That would be the CONSOLEMAP variable in rc.conf.)

Regards,
j

Offline

#6 2008-02-11 22:34:31

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

jbromley wrote:

...add the parameter atkbd.softraw=0 to your kernel boot line.

Wow, where on earth did you find that little morsel of info? I will give it a shot and post my results. I think you're right though about the scancodes being incorrect--I read in one of the man pages about the weird behaviour that kernel 2.6x exhibits.

Thanks!


thayer williams ~ cinderwick.ca

Offline

#7 2008-02-11 22:57:33

zyghom
Member
From: Poland/currently Africa
Registered: 2006-05-11
Posts: 432
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.


Zygfryd Homonto

Offline

#8 2008-02-12 00:38:06

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

Thanks for the link...

Well, I was able to find the true scancodes using the kernel flag, but unfortunately the setkeycodes commands is still unable to change their default binding.  I've also tried changing the Xkb rules in /etc/X11/xorg.conf to no avail. I hate "giving up", but I see little else for me to do. Thanks for the tips though; I've made some notes for future reference.


thayer williams ~ cinderwick.ca

Offline

#9 2008-02-12 05:25:37

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: Scancode/Keycode guru in the house? I'm at my wits end.

How are you checking if setkeycodes is working? I just looked at my setup and when I do dumpkeys it doesn't show keycodes 120 to 124 (where my Fn keys are assigned) as used. However, when I do showkeys, it does show the remapped key codes for these keys. It looks like dumpkeys only shows the configuration from the loaded keymap and does not show changes made with setkeycodes. You've probably already checked this, but I noticed this and thought I'd mention it. If this is not the case, I don't know why setkeycodes wouldn't work.

Good luck,
j

Offline

#10 2008-02-12 12:01:09

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 971
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

yeah, i was on the same journey. i gave up. sometimes it is for the best.


I need real, proper pen and paper for this.

Offline

#11 2008-03-04 22:46:01

jonkristian
Member
From: Norway
Registered: 2007-03-09
Posts: 101
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

jbromley: Mind sharing your scripts from your .xbindkeys smile ?


PROCRASTINATION
is like masturbation...it's good in the beginning, but in the end, you realize
you've just fkd yourself

Offline

#12 2008-03-05 04:31:56

jbromley
Member
From: Pasadena, CA
Registered: 2007-02-04
Posts: 268

Re: Scancode/Keycode guru in the house? I'm at my wits end.

Sure, really there are only two scripts - one to manipulate volume and one to hibernate without being root. There are two versions of the volume script. One uses OSD for volume display and one uses a program called changevol. Here they are:

#!/bin/bash
#
# volume - change volume with OSD notification (there's some cheese in the display!)
command=$(basename $0)
case ${command} in
    toggle_sound)
    action='toggle'
    ;;
    volume_down)
    action='1-'
    ;;
    volume_up)
    action='1+'
    ;;
    *)
    case $1 in
        toggle|mute)
        action='toggle'
        ;;
        down)
        action='1-'
        ;;
        up)
        action='1+'
        ;;
        *)
        ;;
    esac
esac

if [ -n ${action} ]; then
    amixer sset 'Master' ${action} 2>&1 > /dev/null
    amixer sset 'Master Mono' ${action} 2>&1 > /dev/null
    curvol=$(amixer sget 'Master' | tail -n 1 | gawk '{print $5}' | tr -d [%])
    
    if [ ${action} == "toggle" ]; then
    cur_state=$(amixer sget 'Master' | tail -n -1 | gawk '{print $7}')
    if [ $cur_state == "[on]" ]; then
        text="Sound unmuted"
    else
        text="Sound muted"
    fi
    else
    text="Volume ${curvol}"
    fi

    osd_cat --pos=middle --align=center \
    --font=-xos4-terminus-bold-r-*-*-*-320-*-*-*-*-iso10646-1 --color='#33bfcc' \
    --delay=1 --barmode=percentage --percentage=${curvol} \
    --text="${text}"
fi

The changevol program gives you a nice little GTK+ window that shows the volume when changes are made.

#!/bin/bash
#
# volume.changevol
command=$(basename $0)
case ${command} in
    toggle_sound)
    action='-t'
    ;;
    volume_down)
    action='-d 1'
    ;;
    volume_up)
    action='-i 1'
    ;;
    *)
    case $1 in
        toggle|mute)
        action='-t'
        ;;
        down)
        action='-d 1'
        ;;
        up)
        action='-i 1'
        ;;
        *)
        ;;
    esac
esac

if [ -n '${action}' ]; then
    changevol -c 'Master' ${action}
    changevol -c "'Master Mono'" -q ${action}
fi

To use these volume scripts, put them somewhere on your path and symlink the one you want to use to volume_up, volume_down and toggle_sound. Use these three symlinks to do the appropriate thing. Note that in either scripts you may have to edit the channel names "Master" and "Master Mono". (For me, master mono actually controls a subwoofer, so I have to adjust both channels to get even volume changes. You may not need this.)

The hibernate script is used in conjunctions with sudo so users can hibernate without entering the root password. It's just a wrapper:

#!/bin/sh
sudo /usr/sbin/pm-hibernate

mocp is just a console music player and scrot takes screenshots.

Regards,
j

Offline

#13 2008-03-06 18:17:52

jonkristian
Member
From: Norway
Registered: 2007-03-09
Posts: 101
Website

Re: Scancode/Keycode guru in the house? I'm at my wits end.

Very cool, thanks alot:)


PROCRASTINATION
is like masturbation...it's good in the beginning, but in the end, you realize
you've just fkd yourself

Offline

Board footer

Powered by FluxBB