With the idea of remapping all its buttons I bought a Razer Naga, so that I could launch applications and do key-combos with its keypad. My surprise was that, once connected, and the razer daemon running, the qrazercfg tool did not show any sign of button configuration. I got in contact with the programmer of the tool and he told me the Naga cannot customize its buttons by hardware. All each numeric button means is just that, a number. So when I press the button labeled 4 it is exactly as if I had pressed the key 4 on the keyboard.

The problem with this situation is that if i remap a given button (using xbindkeys) also the associated key on the keyboard gets remapped. There should be a way to distinguish both presses.

By testing with xev I realized that the keypad of the Naga and the number keys of the keyboard are practically the same. The only difference is in the "serial" field, as I show next.

This is the output of xev for the keyboard when pressing the key associated with the number 1.

As you can see, the serial field has changed after the button press. This is the only difference I see that I can use in order to distinguish mouse and keyboard and do the remapping of the Naga. It looks like when pressing a keypad button the number of serial advances in one unit.

I have no hope to solve this issue, but I decided to post in the forum to ask for help.

I just found a solution that works quite acceptably. It involves using xbindkeys and xdotool. The first program lets us assign commands to specific mouse buttons, keys or key combos. The second one emulates key presses and releases.

As I explained above, the Naga 12 buttons keypad acts exactly as number keys, and we don't want to bind them directly to commands because that would imply that the number keys on the keyboard would trigger the commands, and this is not desirable. But using a combination of, for example, the windows logo key + a number key would ensure a safe running of commands without the danger of running them by mistake.

Now, the point is to bind the windows logo key to one of the two buttons neighboring the left button of the mouse. Luckily these two extra buttons are recognized by the system as genuine button clicks. So using xbindkeys with xdotool we do the trick, as can be seen in the code below. It is the contents of the .xbindkeysrc file, located at the home directory.

Code:

#Launching applications with a key combo

"dolphin"
Mod4 + 1

"firefox-bin"
Mod4 + 2

"skype"
Mod4 + 3

# Making the button 9 equivalent to windows key

"xdotool keydown 133"
b:9

"xdotool keyup 133"
Release + b:9

"xdotool keydown 133"
m:0x40 + b:9

"xdotool keyup 133"
Release + m:0x40 + b:9

A useful program for getting the keycodes and more info is xev. Using xev we know that Mod4 is the key id for the windows logo, whose keycode is 133. We bind the windows logo key to button 9 in the last part of the config file. There xdotool emulates the keydown and keyup when he button is pushed and released. Note the repetition of the assignments. We need this because the modifier part of the event (m:0x[mod]) isn't the same depending on the previous state of the modifier. You can check this with xev and substitute [mod] by what your system says.

We have bound the windows logo key to one of the buttons of the mouse and by pressing it together with any of the buttons of the keypad any command can be run. So, all in all, a nice solution for making use of the nice array of buttons of the Razer Naga!

Thanks for the tip. Now I am looking for info about setxkbmap but without success. How to write a custom keymap for the mouse? I will post later when I have definite answers. Of course help is very welcome!

I made some advances. Now I can assign any key to the Naga keypad by customizing a xkb_symbols config file and using the -device option of setxkbmap. I already tried mapping the button 1 to the letter A with success. Now my question is: is it possible to map a combination of keys to one physical key of the device? The idea is to press one button of the mouse and act as a key combo to launch an application with xbindkeys.

First, I tweaked one of the symbol profiles used by setxkbmap by assigning to the numeric keys a series of XF86Launch symbols. I named it 'razer'. Then I loaded the symbols to the device, whose id I found with the output of xinput --list. Apparently this step went OK since pressing any of the buttons on the Naga's keypad did not output numbers, as usual, but nothing. I assume it is just outputting the XF86Launches.

The problem I think is in xbindkeys. When I try to map the XF86Launches to a command it does not work as expected. In fact it does nothing, suggesting that xbindkeys does not recognize these symbols.

Is there a way for xbindkeys to recognize the XF86Launches? Are there any other symbols, preferably not used by the keyboard, that I can use for launching commands?

On the one hand it says the number 1 key has been pressed, because 10 is its keycode. On the other it detects XF86Launch0, which is the symbol to which it is mapped with setxkbmap. If I try the same with xbindkeys -k the result is:

Code:

Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"(Scheme function)"
m:0x0 + c:10
XF86Launch0

Basically the same. If I use the first line in .xbindkeysrc config file all I get is the number 1 key, both from keyboard and Naga, mapped to a command. If I use the second nothing happens. So maybe it is a bug in xbindkeys, I don't know. I already googled about it but unsuccessfully. Any idea?

bug #29842: XF86Eject keysym does not work
That's because key matching is always based on keycodes. But for some several keycodes can be mapped to the same keysym, and XKeysymToKeycode only returns the 1st one, which can be different from the one actually generated by the keyboard.

Does this mean that the XF86Launch0 symbol associated to the number 1 button of the Naga by setxkbmap is interpreted by xbindkeys as the same symbol from the keyboard? And that in order for this whole thing to function properly I should indicate to xbindkeys the keycode of the key whose signal it catches, that is the keycode of number 1 key? But that would imply that also the keyboard would run the command as configured in .xbindkeysrc.

Today I tried evrouter and it works very well. It recognizes events generated by different devices and lets you assign actions to them. The good thing (for me) is that it identifies the device from where the event comes, so it can be configured to listen only to the Naga.

In order to use it as normal user, not root, one has to change the owner of the devices before running evrouter, such as:

Code:

chown jose /dev/input/by-id/usb-Razer_Razer_Naga-event-kbd

for example in a script that runs as root at start up. evrouter is very easy to use, just consult its man pages. If someone is interested in knowing specifically what I did, please feel free to ask and I will post my experience.

Finally, the fact that each button of the Naga is mapped to a command does not mean that the symbol associated with it is not recognized as such. For example, pressing number 1 button launches dolphin and outputs the number 1 to the console. In order to avoid this, one can use setxkbmap to define the symbols of the Naga keypad in such a way that they are no longer numbers but XF86Launches, which won't have any visible effect.

So this is a happy day for me and my Naga. Now: time to think what awesome applications all these can have!

First, I tweaked one of the symbol profiles used by setxkbmap by assigning to the numeric keys a series of XF86Launch symbols. I named it 'razer'. Then I loaded the symbols to the device, whose id I found with the output of xinput --list. Apparently this step went OK since pressing any of the buttons on the Naga's keypad did not output numbers, as usual, but nothing. I assume it is just outputting the XF86Launches.

The problem I think is in xbindkeys. When I try to map the XF86Launches to a command it does not work as expected. In fact it does nothing, suggesting that xbindkeys does not recognize these symbols.

Is there a way for xbindkeys to recognize the XF86Launches? Are there any other symbols, preferably not used by the keyboard, that I can use for launching commands?

Hi Jose,

Thanks for all the helpful tips.

I spent hours and hours, but couldn't get the setxkbmap part (the evrouter was a piece of cake). Could you please be so kind to briefly describe the steps? I copied the "keypad" symbols file and changed the mapping of KP0 to KP9 in the x11 section (which loads here by default). Saved the new symbols file as "razer". How do I make it load, so that it recognizes the new functions? I tried with setxkbmap -device 9 -symbols razer but that expectedly did not work (it has no way to run specifically the x11 config), also tried with xkbcomp, but no luck as well.

bug #29842: XF86Eject keysym does not work
That's because key matching is always based on keycodes. But for some several keycodes can be mapped to the same keysym, and XKeysymToKeycode only returns the 1st one, which can be different from the one actually generated by the keyboard.

Does this mean that the XF86Launch0 symbol associated to the number 1 button of the Naga by setxkbmap is interpreted by xbindkeys as the same symbol from the keyboard? And that in order for this whole thing to function properly I should indicate to xbindkeys the keycode of the key whose signal it catches, that is the keycode of number 1 key? But that would imply that also the keyboard would run the command as configured in .xbindkeysrc.

Can you raise my hope with any enlightened post?

You might try to first remove all keycode to keysym mappings for the problematic key and then add the right one (keycode->keysym) using xmodmap. That way I got my XF86Eject and similar keys (which were properly recognized by xev) working with key grabbers. There might be a way to achieve the same using setxkbmap.