I use a Logitech G600 Gaming Mouse which I purchased for Windows gaming, but until now the extra mouse buttons were useless on Linux and I wanted to map these to media keys.
After much googling, I came across this blog post
which detailed the steps necessary to set this up. It’s worth reading, but my post
will be slightly different as I am skipping the xbindkeys
step at the end.
Before I start, I am running Arch Linux so you may need to install various packages on your distribution of choice.
The first step is to grab the vendor and product ID for your mouse. This can be
found by typing lsusb
. In my case, this is ID 046d:c24a Logitech, Inc. G600 Gaming Mouse
- the vendor ID is 046d
and the product ID is c24a
.
Now you need to grab the scancodes of the mouse buttons that you want to use.
To do this, type sudo evtest
and select the correct entry from the list. My mouse
shows two lines: one is the standard mouse functionality and the other represents the extra mouse buttons, masquerading as a USB keyboard.
If your mouse has a modifier button, such as the Logitech G600’s G-Shift, scroll to the bottom of this page for additional instructions.
... snip ...
/dev/input/event17: Logitech Gaming Mouse G600
/dev/input/event18: Logitech Gaming Mouse G600
... snip ...
Select the device event number [0-21]: 18
Press one of your extra mouse buttons and you’ll see a load of text on-screen:
Event: time 1413534756.789835, -------------- EV_SYN ------------
Event: time 1413534756.972846, type 4 (EV_MSC), code 4 (MSC_SCAN), value 7005a
Event: time 1413534756.972846, type 1 (EV_KEY), code 80 (KEY_KP2), value 0
The scancode is the 7005a
at the end of the second line. On the third line, you can see
what it resolves to (KEY_KP2
) - in this case, it maps to number 2 on my numpad. We want to
override this mapping.
Make a note of the scancode for any other buttons and then create a file named
/etc/udev/hwdb.d/70-mouse-map.hwdb
with the following content:
keyboard:usb:v046DpC24A*
KEYBOARD_KEY_7005a=playpause
KEYBOARD_KEY_7005c=previoussong
KEYBOARD_KEY_7005d=playpause
KEYBOARD_KEY_7005e=nextsong
KEYBOARD_KEY_70021=volumedown
KEYBOARD_KEY_70022=mute
KEYBOARD_KEY_70023=volumeup
The first line of this file identifies the device that this should affect - you need to specify the vendor and product IDs from earlier here, with both uppercased.
The second line onwards (note the single space at the beginning of each line) represents each extra mouse button and maps them to a keymap (from this list).
In my case, I’m mapping these directly to XF86Audio
media keys. If you want to ultimately map them to
open various applications then take a look at the blog post I linked to further up.
Once you’ve mapped enough buttons, type sudo udevadm hwdb --update
and then sudo udevadm trigger
to activate the new mappings.
Mice with modifier buttons
If your mouse has a modifier button then you will need to map each button combination using the vendor’s software.
In the case of the Logitech G600, this involved opening the Logitech Gaming Software, switching the mouse mode to on-board memory and changing each modifier and button combination from the default CTRL+NUM to a regular number, letter or character.
Failing to do this will most likely result in evtest
showing the same scancode as the non-modified button does.