Labels

Showing posts with label Shortcuts. Show all posts
Showing posts with label Shortcuts. Show all posts

8 Sept 2014

Logitech G600 in (Arch-)Linux

I like optimizing my workflow and therefore I like potent input devices!

I use the Logitech G600 mouse and it offers an insane amount of buttons. But how do you make use of those in Linux?

If you want to make use of the G-shift functionality and to improve the further configuration-experience, you should (sadly) plug this mouse into a windows machine with the Logitech software installed. Here you are able to define three profiles, which are stored internally in the mouse.
You should start by choosing cool colours for the RGB-LEDs. After this is done you should define all standard mouse buttons, profile-change and g-shift button to be the same for all three profiles. The twelve thumb buttons should have different symbols for every possible case! (normal and g-shift for three profiles = 6 sets. You don't need to make use of all three profiles if you don't need them)
I chose something like {1, 2, 3, ..., 9, 0, ß, ´} for the first profile and the keypad numbers 0 - 9 and keypad + and - for the G-shift case of the first profile. Another possibility would be the letters A - Z. With this you make sure that for example G9 (first thumb button) and G-shift+G9 are received as different events in Linux.
Maybe it's possible to define your wished shortcuts here, but I want to have a more generic way.

Back to Linux:
It didn't take long until I noticed, that this mouse is actually registering two events in /dev/input/ . One for the normal mouse-stuff (like clicking, you know) - and the other for all the fancy extra buttons and functionality. The second one is actually acting like a keyboard.

With

    sudo evtest 

you will be able to detect the scancodes of each button-event. First choose the event corresponding to the "keyboard-part" of the G600 and then hit each combination possible. (G9, G10, ..., G20, G-shift+G9, ... , G-shift+G20, for each profile you want to use)
You are searching for lines like:

    Event: time 1410191730.438246, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7001e

The bold part is the scancode you will need for this specific button.

Now we want to make a rule that those buttons behave differently for this device only. For our rule we should know the vendor and product ID of our USB-device. This is done through
      
    lsusb -v

this leads to something like:
    
    [text]      
    idVendor           0x046d Logitech, Inc.     
    idProduct          0xc24a G600 Gaming Mouse 
    [moretext]

The creation of such a rule is nowadays done through the udev-hwdb (hardwaredatabase). In Arch you have to create a file in /etc/udev/hwdb.d/
with the name

    70-SOMENAME.hwdb

There we need to write the line

    keyboard:usb:v046DpC24A*

followed by many definitions of the form
    
    KEYBOARD_KEY_<hex scan code>=<key code identifier>

where <hex scan code> is the scancode we obtained with evtest and <key code identifier> is a keycode of a currently (unused!) keyboard symbol. (You can find a list of possible keycodes at here)
I used some Japanese stuff, because I'm quite sure that I never have to use a Japanese keyboard. So this looks something like:

    KEYBOARD_KEY_7001e=zenkakuhankaku
    KEYBOARD_KEY_7001f=katakanahiragana       
    KEYBOARD_KEY_70020=katakana    
    KEYBOARD_KEY_70021=hangeul

After this you need to run

    udevadm hwdb --update

and you need to reconnect the device. (e.g. physically)

Now we can use xbindkeys and xautomation to define the shortcuts.
Use 

    xbindkeys -k

for each button. This will result into something like:

    "(Scheme function)"       
        m:0x10+c:191 

Now create a file named ".xbindkeysrc" in your homefolder and add one entry of the above format per button-event. (again: G-shift+GX is separate from GX) The entries could look like this:

    #G18     
    "xte 'keydown Super_L' 'key j' 'keyup Super_L'" 
        m:0x10+c:191+Release 
    #G18 +G-shift    
    "xte 'keydown Super_L' 'keydown Shift_L' 'key j' 'keyup Shift_L' 'keyup Super_L'"       
        m:0x10+c:202+Release

Now just start xbindkeys, and create some way of autostarting xbindkeys and you are done.

I used this procedure to define some Awesome WM shortcuts (like switching the current tag and changing layouts), and to improve browsing in Firefox. (changing tabs, closing tabs, reopen the last tab, back, forward, etc.)   

UPDATE (26.06.2015):

Today I had an issue that the mapping doesn’t work anymore (after an update). Long story short: with
    evdev:input:b*v046DpC24A*  
instead of 
    keyboard:usb:v046DpC24A* 

in the beginning of the hwdb file it worked again.