I have a stylus pen with a button on the side. This button sends a middle click event, and I'd like it to send a right click.

Here are my input devices:

$ xinput
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Microsoft Surface Keyboard Mouse          id=9    [slave  pointer  (2)]
⎜   ↳ Microsoft Surface Keyboard Consumer Control   id=10   [slave  pointer  (2)]
⎜   ↳ Microsoft Surface Keyboard Touchpad       id=11   [slave  pointer  (2)]
⎜   ↳ ipts 1B96:005E UNKNOWN                    id=12   [slave  pointer  (2)]
⎜   ↳ ipts 1B96:005E Touchscreen                id=14   [slave  pointer  (2)]
⎜   ↳ ipts 1B96:005E Mouse                      id=15   [slave  pointer  (2)]
⎜   ↳ ipts 1B96:005E Pen Pen (0)                id=17   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Video Bus                                 id=6    [slave  keyboard (3)]
    ↳ Surface Pro 3/4 Buttons                   id=7    [slave  keyboard (3)]
    ↳ Microsoft Surface Keyboard Keyboard       id=8    [slave  keyboard (3)]
    ↳ ipts 1B96:005E Pen                        id=13   [slave  keyboard (3)]
    ↳ Microsoft Surface Keyboard Consumer Control   id=16   [slave  keyboard (3)]

I created a .conf file in /etc/X11/xorg.conf.d (or in /usr/share/X11/xorg.conf.d and get the same problem) as follows:

Section "InputClass"
    Identifier  "ipts 1B96:005E Pen Pen (0)"
    Option  "ButtonMapping" "1 3 2 4 5 6 7"

The problem is, my .conf file remaps my touchpad as well as the stylus pen. Using "ipts 1B96:005E Pen" as the identifies has the same problem.

Using xinput directly, with "xinput set-button-map "ipts 1B96:005E Pen Pen (0)" 1 3 2 4 5 6 7" works, but I can't make it survive events like suspend.

What's the best was to fix this configuration?

1 Answer 1


As described in the xorg.conf man page, you need to use one or more of the Match parameters within your InputClass stanza to restrict the Options you set there (in this instance, the ButtonMapping) to the intended devices. Those parameters are:

  • MatchProduct
  • MatchVendor
  • MatchDevicePath
  • MatchPnPID
  • MatchUSBID
  • MatchIs... (This one needs a device type to be complete and accepts only boolean values; see below for an example)

Note: A common stumbling block encountered with the MatchUSBID parameter has to do with the case used for any hexadecimal letters found in it. If you get the id from the lsusb command you're fine as it produces output with only lowercase letters, but as your example illustrates perfectly, other commands like xinput output hexadecimal strings using uppercase letters. Quoting the manual page linked above:

The ID is constructed as lowercase hexadecimal numbers separated by a ’:’.

From the command output you provided in your question I can construct an InputClass stanza with these Match conditions that should solve your problem, though I'd advise trying different subsets of them and ultimately using the one that produces the behavior you want using the fewest number of Match entries (for simplicity's sake but more so for portability).

Section "InputClass"
  Identifier     "Surface Pen"
  MatchProduct   "Pen Pen (0)"
  MatchVendor    "ipts"
  MatchUSBID     "1b96:005e"
  MatchIsPointer "true"
  Option         "ButtonMapping" "1 3 2 4 5 6 7"
  • 1
    Thanks. This still needs identifier, though, otherwise X fails to start. Feb 23, 2019 at 0:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .