[plug] USB Keypad Shennanigans

Jeremy Kerr jk at ozlabs.org
Fri Jul 26 00:46:26 UTC 2013


Hi Onno,

> I've learnt that there is much voodoo in this, lots of contradictory
> information and a basic assumption that you'd just want to use some or
> other layout.
> 
> I've been unable to locate any information on how to create a layout
> that actually generates a range of bogus keys from pressing a key on the
> keypad.

There are three "layers" involved here: the hardware scancode, the
kernel input event and the X input event. There are mappings for
(scancode -> kernel event) and (kernel event -> X event).

If you aren't seeing the necessary events appearing, I'd suggest
updating the scancode -> kernel event mapping; this way, you're not
reliant on X, and you can set a per-device mapping (IIRC, X events are
for the multiplexed input queue, so mappings apply to all devices).

Here's how you'd update the scancode map:

Quick rundown:

1) See which input device number your keypad is using.

    sudo lsinput

   - if your keypad is listed under /dev/input/event6, then your
     device number if 6

2) See which scancodes are being generated from the keypad, and which
   EV_KEY events are being generated:

    sudo input-events $device-number

   - then press some keys on your keypad.

   Each keypress will generate the following:

   08:21:49.636874: EV_MSC MSC_SCAN 458978
   08:21:49.636879: EV_KEY KEY_LEFTMETA (0x7d) pressed

   This shows that the hardware scancode 458978 (0x700E2) was emitted
   by my keyboard, which the kernel translated to a left-meta keypress

   If you find that the kernel events aren't suitable for you, you can
   remap them. This is what I have done to switch the left meta and
   left alt keys on my keyboard:

   $ cat /lib/udev/keymaps/apple-keyboard
   0x700e2	leftmeta
   0x700e3	leftalt

   - this is the scancode -> kernel event mapping that I would like.
   Take a look in /usr/include/linux/input.h for possible event names
   (listed as KEY_*).

   you can manually load this keymap with:

     /lib/udev/keymap input/event6 /lib/udev/keymaps/apple-keyboard

   however, you probably want to do it in a udev rule:

   $ cat /etc/udev/rules.d/96-apple-keymap.rules
   ACTION=="add", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="05ac",
     ENV{ID_MODEL_ID}=="024f", RUN+="keymap $name apple-keyboard"

   - this tells udev to load the above "apple-keyboard" keymap when
     this particular device is detected


If you need to check out which X events are being generated, I'd suggest
using xev. However, if you're using X, you'll probably have some nifty
tool to detect key events and allow you to map them to run your suitable
audio-output command.

Hope this helps,


Jeremy


More information about the plug mailing list