[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Keyboard remapping



On 2013-03-01 14:49:09 +1100, Daniel Dalton wrote:
> On Fri, Mar 01, 2013 at 03:38:23AM +0100, Vincent Lefevre wrote:
> > On 2013-03-01 12:07:07 +1100, Daniel Dalton wrote:
> > > I've ran showkeys and found that the fn key has a key code. 
> > > 
> > > However, when I do fn+j for example only the fn key code is noted. 
> > 
> > What if you start showkeys in scan code dump mode?
> 
> How to do this?

The showkey man page (I suppose you meant showkey, not showkeys) says:

       -s --scancodes
              Starts showkey in scan code dump mode.

I haven't tried though, as showkey doesn't seem to work under X11
(contrary to /lib/udev/keymap).

> > > In addition to this I've discovered that my keyboard does not have an
> > > application key or a right windows key (the key you press to get a
> > > context menu in a gui).... It is the equivalent of right clicking
> > > basically. Since I'm blind and I can't use a mouse this key is kind of
> > > important. How could I bind right alt to act as this key? 
> > 
> > If you want to do this only for this keyboard (not for some USB
> > keyboard that you would connect), you can use /lib/udev/keymap
> > to map the scancode of the key to the wanted keycode (I don't
> > have such a key, so I don't know).
> 
> How to do that though /lib/udev/keymap appears binary? 

The documentation is here: /usr/share/doc/udev/README.keymap.txt.gz

For instance, in my case, I had written a file
/etc/udev/keymaps/apple-aluminum containing:

0x70035 86      # Left to z: 102nd (providing backslash bar)
0x70064 grave   # Left to 1: grave notsign
0x70068 insert  # F13

for the remappings I needed. The first number is the scan code, the
second word is the key code or some associated symbol corresponding
to the KEY_* macros from "/usr/include/linux/input.h". Due to a bug
in the udev keymap utility, I had to use the key code 86 instead of
the symbol 102nd above (though I've now written a patch, see Debian
bug 654947).

To do the remapping (mainly for testing) of my USB keyboard, I did:

$ /lib/udev/findkeyboards
USB keyboard: input/event2
AT keyboard: input/event0
Unknown type: input/event18

to get the device name, here input/event2, then:

$ sudo /lib/udev/keymap input/event2 /etc/udev/keymaps/apple-aluminum
Remapped scancode 0x70035 to 0x56 (prior: 0x29)
Remapped scancode 0x70064 to 0x29 (prior: 0x56)
Remapped scancode 0x70068 to 0x6e (prior: 0xb7)

After testing, I could do that automatically with a udev rule
/etc/udev/rules.d/98-apple-keyboard.rules containing:

# Apple Aluminum USB keyboard
ACTION!="remove", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="05ac", ENV{ID_MODEL_ID}=="0221", RUN+="keymap $name /etc/udev/keymaps/apple-aluminum"

Here's the documentation I used:
  * http://reactivated.net/writing_udev_rules.html by Daniel Drake
  * udev(7) man page
  * /usr/share/doc/udev/README.keymap.txt.gz
  * /lib/udev/rules.d/95-keymap.rules (examples)

> Is it possible to do this through xmodmap or siilar I only need it
> for X (gnome).

xmodmap is obsolete, now broken (due to XKB features), and no longer
supported. It shouldn't be used any longer. XKB (setxkbmap / xkbcomp
/ ...) is the right solution for X, but some keys may need something
more low level. And XKB settings are lost after suspend / resume,
which is rather annoying (Debian bug 633849).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Reply to: