Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Desktop Environments
  • Search

Razer Naga and its buttons

Problems with GUI applications? Questions about X, KDE, Gnome, Fluxbox, etc.? Come on in. NOTE: For multimedia, go up one forum
Post Reply
Advanced search
15 posts • Page 1 of 1
Author
Message
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

Razer Naga and its buttons

  • Quote

Post by jose.maria » Sun Sep 30, 2012 9:36 am

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: Select all

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: Select all

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.
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Sun Sep 30, 2012 4:55 pm

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: Select all

#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!
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Mon Oct 01, 2012 1:48 am

setxkbmap has a "-device" option, maybe writing a custom keymap for that would be a better method.
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Mon Oct 01, 2012 5:47 pm

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!
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Mon Oct 01, 2012 8:25 pm

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.
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Tue Oct 02, 2012 1:21 am

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.
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Tue Oct 02, 2012 3:58 pm

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?
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Tue Oct 02, 2012 5:09 pm

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.
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Tue Oct 02, 2012 7:14 pm

Actually I am a little bit confused with the output of xev, when pressing the button labeled 1 in the Naga:

Code: Select all

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: Select all

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?
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Tue Oct 02, 2012 9:47 pm

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
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? :)
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Tue Oct 02, 2012 11:01 pm

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...
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Tue Oct 02, 2012 11:26 pm

OK, thanks for the support. Tomorrow I will try evrouter. Now: to bed...
Top
jose.maria
n00b
n00b
User avatar
Posts: 24
Joined: Tue Sep 04, 2012 6:59 pm
Location: In the garden

  • Quote

Post by jose.maria » Wed Oct 03, 2012 2:11 pm

I am happy! :D

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: Select all

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!
Top
zhvihti
n00b
n00b
Posts: 1
Joined: Wed Oct 17, 2012 11:40 pm

  • Quote

Post by zhvihti » Wed Oct 17, 2012 11:47 pm

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: Select all

$ 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: Select all

setxkbmap -model pc105 -layout us,bg -variant ,bas_phonetic -option grp:alt_shift_toggle
Top
Small_Penguin
Tux's lil' helper
Tux's lil' helper
Posts: 146
Joined: Fri May 27, 2005 6:24 pm

  • Quote

Post by Small_Penguin » Thu Oct 18, 2012 9:27 pm

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
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.
Top
Post Reply

15 posts • Page 1 of 1

Return to “Desktop Environments”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Authors
Gentoo is a trademark of the Gentoo Foundation, Inc. and of Förderverein Gentoo e.V.
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-4.0 license.
The Gentoo Name and Logo Usage Guidelines apply.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy