# Per-device USB keyboard remapping/ xmodmap - can it be done?

## tiktak

Hey all, does anyone of you know whether (and if so, how) it is possible to either:

 remap scancodes to other scancodes of a keyboard on a per-device basis (i.e. when a USB keyboard is attached, run some program to that effect (I learned of none so far)), or

  "at least" run an Xmodmap keycode map on only a specific device (parallel to configurations of other attached keyboards; is it even possible to have per-device scancode->keycode mappings in Xorg simultaneously ??)

What I basically need (for my USB-attachable num-pad keyboard) is either additional scancodes (not colliding with the primary keyboard) I can freely map to keysyms, or at least a separate mapping of the scancodes for just the numpad to a keymap unrelated to the xmodmap of the primary keyboard.

Any hints (even if you know for sure it's currently impossible ^_^) would be very much appreciated. THX1e6 in advance!

EDIT: Another alternative: if you know of a program / usb/kernel/something / Xorg driver that can capture all input from a USB keyboard on a per-device basis and not send it to the normal input layers, but instead to a userspace program / daemon, that might help too.. I will keep looking too...

----------

## dtor

 *tiktak wrote:*   

> Hey all, does anyone of you know whether (and if so, how) it is possible to either:
> 
>  remap scancodes to other scancodes of a keyboard on a per-device basis (i.e. when a USB keyboard is attached, run some program to that effect (I learned of none so far)), or
> 
>   "at least" run an Xmodmap keycode map on only a specific device (parallel to configurations of other attached keyboards; is it even possible to have per-device scancode->keycode mappings in Xorg simultaneously ??)
> ...

 

To alter keymap of a particular keyboard you need to issue EVIOCSKEYCODE ioctl on corresponding /dev/input/eventX node. This currently works for PS/2 keyboards and some others. The ability to do that for USB keyboards is coming in 2.6.22.

 *Quote:*   

> 
> 
> EDIT: Another alternative: if you know of a program / usb/kernel/something / Xorg driver that can capture all input from a USB keyboard on a per-device basis and not send it to the normal input layers, but instead to a userspace program / daemon, that might help too.. I will keep looking too...

 

To achieve this your application should open corresponding /dev/input/eventX device and issue EVIOCGRAB ioctl. This will make sure that your application is the only consumer of input evenst from that particular device.

Hope this helps.

----------

## tiktak

I usually do not zombiefy my older topics, but i must say "Thank you very much!" for your answer. You gave a solution not only for 1 of the possibilities, but both!  :Smile: 

----------

