Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping a key based on the device the key is on? (Linux)

I own a Razer Naga Mouse, essentaly it has a small numpad on the side of it. I want to remap these keys to different unused keys or to bash commands. I can do this easily by using xev to grab the keycode (for instance the "1" on the mouse is keycode 87) and then I can use xmodmap to bind the keycode to a different key.

However the numpad on my keyboard will also inherit this as the keycode is the same, what I noticed though is that the "serial" is different.

For instance here is the output from xev when pressing the "1" button on my mouse numpad.

KeyPress event, serial 34, synthetic NO, window 0x1c00001,
root 0x1ae, subw 0x0, time 2179878, (170,-2), root:(198,345),
state 0x0, keycode 87 (keysym 0xff9c, KP_End), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x1c00001,
root 0x1ae, subw 0x0, time 2179966, (170,-2), root:(198,345),
state 0x0, keycode 87 (keysym 0xff9c, KP_End), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

and here is the output when pressing "1" on my keyboards numpad

KeyPress event, serial 35, synthetic NO, window 0x1c00001,
root 0x1ae, subw 0x0, time 2180261, (170,-2), root:(198,345),
state 0x0, keycode 87 (keysym 0xff9c, KP_End), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1c00001,
root 0x1ae, subw 0x0, time 2180341, (170,-2), root:(198,345),
state 0x0, keycode 87 (keysym 0xff9c, KP_End), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

Is there anyway I could map the keys on my mouse based on this?

like image 959
Evan Purkhiser Avatar asked Oct 13 '22 22:10

Evan Purkhiser


2 Answers

Instead of xmodmap, try using setxkbmap and xkbcomp. The xkbcomp command lets you specify an input device ID (using the -i option).

To get a list of device IDs run xinput --list. (FWIW, my Razer Salmosa was clearly labeled as "Razer Razer Salmosa".)

Here's how I converted my USB keyboard (ID 16) to use the German key mapping, while keeping my laptop keyboard on a US mapping:

setxkbmap de -print | xkbcomp - -i 16 $DISPLAY

I don't really know how to set up xkb mappings, but I found a tutorial that looks pretty good.

like image 80
Dan Cecile Avatar answered Oct 18 '22 01:10

Dan Cecile


Ok Solved. Follow instructions on this wiki https://github.com/graph/Razer-Naga-HotKey/wiki/How-to-get-Razer-Naga-HotKeying-Working-on-Debian

like image 27
over_optimistic Avatar answered Oct 18 '22 02:10

over_optimistic