I would like to remap the "Windows button" on MS Sculpt Comfort Mouse to another button (eg. "Back" button) on my Linux machine (Linux Mint 18.2 "Sonya").

According to xinput list, the mouse is recognized as a pointer device (id=12).

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Microsoft Sculpt Comfort Mouse            id=12   [slave  pointer  (2)]
⎜   ↳ FocalTechPS/2 FocalTech FocalTech Touchpad    id=15   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Chicony USB Keyboard                      id=9    [slave  keyboard (3)]
    ↳ Chicony USB Keyboard                      id=10   [slave  keyboard (3)]
    ↳ USB2.0 UVC HD Webcam                      id=11   [slave  keyboard (3)]
    ↳ Asus WMI hotkeys                          id=13   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=14   [slave  keyboard (3)]

According to xinput test 12 the Super_L key (keycode 133) is generated by the mouse when the "Windows button" is pressed on the mouse.

key press   133 
key release 133 

Now, I need to remap the key for this particular device to another key. I would do it using setxkbmap tool (described in How to remap keys under Linux for a specific keyboard only).

My script is as follows:

    xinput list | sed -n 's/.*Microsoft Sculpt Comfort Mouse.*id=\([0-9]*\).*/\1/p'
[ "$remote_id" ] || exit

# remap Windows button on MS Sculpt Mouse to Back button

mkdir -p /tmp/xkb/symbols
cat >/tmp/xkb/symbols/custom <<\EOF
xkb_symbols "remote" {
    key <LWIN> { [ XF86Back ]        };

setxkbmap -device $remote_id -print | sed 's/\(xkb_symbols.*\)"/\1+custom(remote)"/' | xkbcomp -I/tmp/xkb -i $remote_id -synch - $DISPLAY 2>/dev/null

I have also tried similar approach described in Remap/change your secondary/usb keyboard keys. Tried to swap codes eg. for <LWIN> and <VOL+>. But without success, mouse's Windows key is still interpreted as Windows key.

Then I tried remapping the Windows key (swapped with ) on my USB keyboard (id=9) using the second approach (pure xkbcomp) and it worked, BUT also changed behavior of the mouse's button in the same way (regardless how was the button mapped for the mouse). The weird thing is, when I press the Windows button on the laptop's built-in keyboard (not remapped) and then on mouse, it is interpreted as Windows button. When I press the Windows button on my USB keyboard (remapped to VOL+) and then on the mouse, it is interpreted as VOL+. May be related to Bug 91571 - xkb set via xkbcomp does not seem to apply to -i (or does not stick if used on general device).

Unfortunately, I am not able to remap the button only for the particular device.

1) May be the xkbcomp tool works correctly with 'slave keyboard' devices only? (Not with 'slave pointer')

2) Is there a way to treat this mouse as 'slave keyboard'?

3) Or is there another way to remap 'Windows button' for this particular device only (and not for the main USB keyboard)?


Answering my own question #3: udev can make it. My /etc/udev/hwdb.d/10-ms-sculpt-back.hwdb file:

# remap MS Sculpt Comfort Mouse (Bluetooth) Windows key to Back key

Thanks to Map scancodes to keycodes and How to find the .hwdb header of a general input device?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.