View previous topic :: View next topic |
Author |
Message |
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Sun Sep 30, 2012 9:36 am Post subject: Razer Naga and its buttons |
|
|
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.
Code: | KeyPress event, serial 40, synthetic NO, window 0x3800001,
root 0xb1, subw 0x3800002, time 44155357, (48,31), root:(1148,438),
state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
XLookupString gives 1 bytes: (31) "1"
XmbLookupString gives 1 bytes: (31) "1"
XFilterEvent returns: False
KeyRelease event, serial 40, synthetic NO, window 0x3800001,
root 0xb1, subw 0x3800002, time 44155435, (48,31), root:(1148,438),
state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
XLookupString gives 1 bytes: (31) "1"
XFilterEvent returns: False |
And this is the same for the Naga button associated with the number 1.
Code: | KeyPress event, serial 40, synthetic NO, window 0x3800001,
root 0xb1, subw 0x0, time 44319985, (131,78), root:(1231,485),
state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
XLookupString gives 1 bytes: (31) "1"
XmbLookupString gives 1 bytes: (31) "1"
XFilterEvent returns: False
KeyRelease event, serial 41, synthetic NO, window 0x3800001,
root 0xb1, subw 0x0, time 44320138, (131,78), root:(1231,485),
state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
XLookupString gives 1 bytes: (31) "1"
XFilterEvent returns: False |
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. |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Sun Sep 30, 2012 4:55 pm Post subject: |
|
|
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! |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Mon Oct 01, 2012 1:48 am Post subject: |
|
|
setxkbmap has a "-device" option, maybe writing a custom keymap for that would be a better method. |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Mon Oct 01, 2012 5:47 pm Post subject: |
|
|
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! |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Mon Oct 01, 2012 8:25 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Tue Oct 02, 2012 1:21 am Post subject: |
|
|
It might make more sense to map the buttons to symbols like XF86Launch[1-F]. That is, assuming things like xbindkeys pick it up properly; even normal keyboards don't always play nice with remapping. |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Tue Oct 02, 2012 3:58 pm Post subject: |
|
|
I have made some progress.
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? |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Tue Oct 02, 2012 5:09 pm Post subject: |
|
|
Try it with xev, that should print out every keycode pressed. If it doesn't work with xbindkeys then I suspect it's a bug in that program - I've had problems like this in it before. |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Tue Oct 02, 2012 7:14 pm Post subject: |
|
|
Actually I am a little bit confused with the output of xev, when pressing the button labeled 1 in the Naga:
Code: | KeyPress event, serial 40, synthetic NO, window 0x3400001,
root 0xb1, subw 0x0, time 13217040, (124,33), root:(1224,440),
state 0x0, keycode 10 (keysym 0x1008ff40, XF86Launch0), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False |
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? |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Tue Oct 02, 2012 9:47 pm Post subject: |
|
|
My hope is diminishing.
I found a bug report with answer that may throw some light to this problem.
http://savannah.nongnu.org/bugs/?29842
Quote: | 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? |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Tue Oct 02, 2012 11:01 pm Post subject: |
|
|
Ahh, that would explain things. I've noticed often other programs detect the keys right but xbindkeys won't. Not sure what option you have here, except maybe look for an alternative to xbindkeys... |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Tue Oct 02, 2012 11:26 pm Post subject: |
|
|
OK, thanks for the support. Tomorrow I will try evrouter. Now: to bed... |
|
Back to top |
|
|
jose.maria n00b
Joined: 04 Sep 2012 Posts: 24 Location: In the garden
|
Posted: Wed Oct 03, 2012 2:11 pm Post subject: |
|
|
I am happy!
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! |
|
Back to top |
|
|
zhvihti n00b
Joined: 17 Oct 2012 Posts: 1
|
Posted: Wed Oct 17, 2012 11:47 pm Post subject: |
|
|
jose.maria wrote: | I have made some progress.
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.
Thanks.
Here is my current config:
Code: | $ setxkbmap -print
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+bg(bas_phonetic):2+inet(evdev)+group(alt_shift_toggle)" };
xkb_geometry { include "pc(pc105)" };
}; |
which is equivalent to:
Code: | setxkbmap -model pc105 -layout us,bg -variant ,bas_phonetic -option grp:alt_shift_toggle |
|
|
Back to top |
|
|
Small_Penguin Tux's lil' helper
Joined: 27 May 2005 Posts: 140
|
Posted: Thu Oct 18, 2012 9:27 pm Post subject: |
|
|
jose.maria wrote: | My hope is diminishing.
I found a bug report with answer that may throw some light to this problem.
http://savannah.nongnu.org/bugs/?29842
Quote: | 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. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|