Logitech M535 in Linux

I just bought a Logitech M535 Bluetooth mouse. It has tilting wheel but it's mapped to "back" and "forward" buttons. To get it work as horizontal scrolling I wrote this script:

#! /bin/dash

MOUSE_ID=`xinput list | grep -o 'M535.*pointer' | sed 's/^.*id=\([0-9]*\)[\t].*$/\1/')`
xinput set-button-map $MOUSE_ID 1 2 3 4 5 8 9 6 7 10 11 12

Unfortunately, in this way, scolling buttons are not repeating.

Moreover the mouse also has an extra button, which sends ALT+TAB (through a "fake" keyboard):

ignazio@ignazio-HP:~$ xinput | grep M535
⎜   ↳ Bluetooth Mouse M336/M337/M535            id=15   [slave  pointer  (2)]
    ↳ Bluetooth Mouse M336/M337/M535            id=16   [slave  keyboard (3)]
ignazio@ignazio-HP:~$ xinput test 16
key press   64 
key press   23 
key release 23 
key release 64 

How can I bind this button to something other?

I tried to use xbindkeys but could not make it intercept ALT+TAB. Moreover, even if I could, I want to only intercept from the fake keyboard from the mouse, and I couldn't find any way to filter devices in xbindkeys.

I also know there are kernel modules for similar Logitech mouses (see https://github.com/CzBiX/logitech-m560), but this one is not supported.


I solved the horizontal scrolling by using key-mapper gui software, and then mapping the left wheel button (BUTTON SIDE) to wheel(right,1); and the right wheel button to wheel(left,1).


I solved using hwdb. I created /etc/udev/hwdb.d/10-m535.hwdb:

evdev:input:b0005v046DpB016e1203-*
 KEYBOARD_KEY_700e2=reserved
 KEYBOARD_KEY_7002b=leftmeta

Then:

sudo udevadm hwdb --update
sudo udevadm trigger

And turn off and on the mouse. It works now, I bound the meta (Windows) key.

I think this solution could be made so the xinput set-button-map is not required (and maybe I can solve the problem that buttons arr not repeating)... But I couldn't find the keycodes for buttons 6 and 7 (scroll left and right). I found the scancodes:

evdev:input:b0005v046DpB016e1203-*
 KEYBOARD_KEY_700e2=reserved
 KEYBOARD_KEY_7002b=leftmeta
 KEYBOARD_KEY_90004=??? (scroll left - mouse button 6)
 KEYBOARD_KEY_90005=??? (scroll right - mouse button 7)

I tried the decimal values for BTN_SIDE, BTN_EXTRA, BTN_BACK, BTN_FORWARD, BTN_6, BTN_7 (as defined in /usr/include/linux/input-event-codes.h) with no luck.

Another mouse, with horizontal scrolling working out-of-the-box has the following evtest output:

Event: time 1522616506.145899, -------------- SYN_REPORT ------------
Event: time 1522616507.105926, type 2 (EV_REL), code 6 (REL_HWHEEL), value 1
Event: time 1522616507.105926, -------------- SYN_REPORT ------------
Event: time 1522616508.191962, type 2 (EV_REL), code 6 (REL_HWHEEL), value -1

Can I somehow specify an EV_REL event with value for keycode in hwdb file?