You are not logged in.

#1 2009-08-03 10:57:44

jzxu
Member
Registered: 2008-06-23
Posts: 10

scan code for hyper key

I bought a programmable keyboard recently for which I can program the hardware scan code of each key. I would like to have a key that is recognized in X using the default xkb rules as the hyper key, but I can't figure out for the life of me how xkb translates hardware scan codes into "keycodes" which are then mapped to symbols in the /usr/share/X11/xkb/keycodes files. Basically, if someone can tell me how X goes from hardware scan codes to keycodes, or just what the scan code is for hyper in the default X keyboard config, I would appreciate it immensely.

Offline

#2 2009-08-03 11:17:37

miau
Member
Registered: 2009-05-06
Posts: 202

Re: scan code for hyper key

Do you mean the "Windows key"? For the windowskey showkey -s shows "0xe5 0x5b" for pressing and "0xe5 0xdb" for releasing the key.

Offline

#3 2009-08-04 01:02:56

jzxu
Member
Registered: 2008-06-23
Posts: 10

Re: scan code for hyper key

Do you mean the "Windows key"?

No, I know the scan codes for the windows keys, and those are by default mapped to Super_L and Super_R.

Offline

#4 2009-08-04 01:48:53

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: scan code for hyper key

maybe xmodmap would help?


neutral

Offline

#5 2009-08-04 02:19:49

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: scan code for hyper key

pacman -Ql xkeyboard-config

will list all the files in that package.

Grepping for Hyper leads to <HYPR>. Grepping for that shows a definition of 207 in /usr/share/X11/xkb/keycodes/evdev and a definition of 128 in xfree86. I haven't gone and read those files, but perhaps this points you in a helpful direction. I've actually gotten comfortable with some chunk of the xkeyboard-config files, but there's lots of it that's still voodoo. Including this.

Offline

#6 2009-08-04 02:36:12

Bregol
Member
Registered: 2008-08-15
Posts: 175

Re: scan code for hyper key

From what I understand, the hardware code turns into a number code for X, which then gets named by X as XF86Cut for example.  I had some keys that nothing detected, so I had to start from the bottom and define from there.  In /etc/rc.local, I put:

setkeycodes e025 137

to set the key e025 (i think the hardware code?) as key 137, which X is able to use now.  To have X set that key 137 as XF86Cut (or Hyper key or whatever), I use xmodmap /etc/X11/Xmodmap which says:

keycode 137 = F21

which tells X that I now have a F21 button.

Thats about all I remember off the top of my head, but if you want, I can go back and try to figure out more of what I did.

edit: this is how i think i figured out how to set the first half: http://wiki.archlinux.org/index.php/Setkeycodes
this is how i did the second half: http://cweiske.de/howto/xmodmap/allinone.html

hope this helps, I only have a basic understanding of how to map keys (from having a couple keys not work by default)

Last edited by Bregol (2009-08-04 02:45:56)


Nai haryuvalyë melwa rë

Offline

#7 2009-08-04 10:19:50

jzxu
Member
Registered: 2008-06-23
Posts: 10

Re: scan code for hyper key

Thanks for the replies, everyone. So after seeing this thing about setkeycodes, I thought that maybe there was also a getkeycodes, and surely enough there was. Running it gets you a table like this:

Plain scancodes xx (hex) versus keycodes (dec)
for 1-83 (0x01-0x53) scancode equals keycode

 0x50:   80  81  82  83  99   0  86  87
 0x58:   88 117   0   0  95 183 184 185
 0x60:    0   0   0   0   0   0   0   0
 0x68:    0   0   0   0   0   0   0   0
 0x70:   93   0   0  89   0   0  85  91
 0x78:   90  92   0  94   0 124 121   0

Escaped scancodes e0 xx (hex)

e0 00:    0   0   0   0   0   0   0   0
e0 08:    0   0   0   0   0   0   0   0
e0 10:  165   0   0   0   0   0   0   0
e0 18:    0 163   0   0  96  97   0   0
e0 20:  113 140 164   0 166   0   0   0
e0 28:    0   0 255   0   0   0 114   0
e0 30:  115   0 172   0   0  98 255  99
e0 38:  100   0   0   0   0   0   0   0
e0 40:    0   0   0   0   0 119 119 102
e0 48:  103 104   0 105 112 106 118 107
e0 50:  108 109 110 111   0   0   0   0
e0 58:    0   0   0 125 126 127 116 142
e0 60:    0   0   0 143   0 217 156 173
e0 68:  128 159 158 157 155 226   0 112
e0 70:    0   0   0   0   0   0   0   0
e0 78:    0   0   0   0   0   0   0   0

which shows that a scan code of e068 maps to 128, the keycode for Hyper, by default. Great, problem solved.

Unfortunately, when I fired up the keyboard programming software, it wouldn't let me assign a scan code of e068 to any keys, for some unexplained reason. Okay, so I use an unmapped scan code, 0x68,  that it does allow me to use. I figured I'd use setkeycodes to set 0x68 to map to 128. But now when I run showkey -s, the key that I thought I programmed to 0x68 gives 0xe078, with a keycode of 192, even though getkeycodes suggests that 0xe078 is unmapped. I even tried booting the kernel with the atkbd.softraw=0 parameter, to no avail. Furthermore, when I run xev in an X session, the keycode for the key in question now shows up as 249.

By this point, I had no idea what was going on anymore, so I just gave up and used xmodmap to set keycode 249 to Hyper_R. I now have a Hyper key, but I can only get it via a series of obscure commands, rather than something that works out of the box. Oh well.

If anyone can explain what was going on here, I'd still like to know, just out of curiosity.

Thanks again.

Offline

#8 2009-08-06 11:11:08

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: scan code for hyper key

One thing I notice is that ou're talking about both getkeycodes and X. You should know that the whole {showkey, dumpkeys, loadkeys, keymaps, setkeycodes, getkeycodes } set of commands (read all of those manpages) affect the keymapping in your linux consoles (what used to be /dev/vc/1 etc and are now /dev/tty1 etc), not the keymapping in X. The keymapping in X is shown/determined by { setxkbmap, xkbcomp, xev, xmodmap, and the files that package extra/xkeyboard-config installs in /usr/share/X11/xkb/}. These are independent paths. Presumably there's some point at which they start out with the same input, and I appreciate that what you're trying to do is change things upstream from there, in your hardware. But these tools seem to be wholly independent from each other.

Maybe you're aware of this already...

jzxu wrote:

I figured I'd use setkeycodes to set 0x68 to map to 128. But now when I run showkey -s, the key that I thought I programmed to 0x68 gives 0xe078, with a keycode of 192, even though getkeycodes suggests that 0xe078 is unmapped.

I'm not sure why you're seeing this disparity btw what you think you've programmed the keyboard to produce as a scan code and what the kernel is reading. This is showing up before you use setkeycodes, right? man setkeycodes says something relevant:

In 2.6 kernels raw mode, or scancode mode, is not very raw  at  all. The code  returned by showkey -s will change after use of setkeycodes.  A kernel bug. See also showkey(1).

Not sure whether this "bug" still obtains or not. But if you know you're getting funny results from showkey -s before you even introduced setkeycodes into the mix, then this can be ignored.

Also, I dunno whether changes you make wth setkeycodes will affect X. Perhaps they will, perhaps not. Changes made a bit downstream from this definitely DO NOT show up in X.

Last edited by Profjim (2009-08-06 11:21:39)

Offline

Board footer

Powered by FluxBB