Primary button goes back to default on external mouse

Ask Ubuntu Asked by flipjacob on December 19, 2020

I’m left-handed, so I have my primary mouse button set to the right button. This works fine on my touchpad buttons, and it used to work fine on my external Bluetooth mouse as well. But now suddenly, each time I connect the external mouse, the primary button on the mouse is the left one, while the touchpad primary button is still the right one. I can solve this by going to Settings > Mouse & Touchpad > Primary Button and set it to Left and then to Right. Of course, I’d rather not have to do this each time the mouse reconnects. Any suggestions?

2 Answers

I use a KVM switcher box and so I have the same issue every time I switch since upgrading.

At the moment I have this quick and dirty script. Run it in a terminal as the logged in user;

xinput list | grep Mouse | sed -nre 's/^.*sid=([0-9]+)s.*$/1/p' | xargs -r -I '{}' echo xinput set-button-map {} 3 2 1

Hope to get something better but should be useful for now.

For completeness, it's worth noting that you can also use the mouse settings UI tool, and change the primary button to right handed and then back to left handed.


I now have a more convenient solution that is automated for each kvm switch, but it's still a hacky/dirty solution, and I run a script after login...

Customise the following for your vendor id and product id, based on output of lsusb. Where the hex number with a colon in the middle is the {idvendor}:{idproduct} for your mouse. Also, as flipjacob adds, customise "Mouse" string in the grep statement to your match what you get from xinput.

Create a file (as root) /etc/udev/rules.d/80-force-left-handed-mouse-on-plugin-event.rules with the following contents

ATTRS{idVendor}=="045e", ATTRS{idProduct}=="0047", ACTION=="bind", RUN+="/root/"

Create the script that it will run (as root) /root/


umask 0000
echo $ACTION >> /tmp/mouse-flag
date >> /tmp/mouse-flag

And finally create the script to pick up the 'notification' in the context of the logged in user. I run this after logging in in a terminal and leave it running there.

Listener script $HOME/


echo "" > /tmp/mouse-flag

tail -qfn 0 /tmp/mouse-flag 2>/dev/null | while read s
  #inotifywait -e create /tmp/mouse-flag
  echo reset mouse $s
  xinput list | grep Mouse | sed -nre 's/^.*sid=([0-9]+)s.*$/1/p' | xargs -I '{}' xinput set-button-map {} 3 2 1

  #sleep 5

It fires the listener loop 3 times for me, but that is of little consequence for something I hope to throw away soon.

Correct answer by user1142827 on December 19, 2020

I had the same issue and after much searching, this worked for me: Open Startup Applications Preferences and Add the following command

xmodmap -e "pointer = 3 2 1"

This worked immediately and persists after a re-start, and persists when the bluetooth mouse re-awakens from inactivity.

Running 20.10 - hope this bug gets fixed soon.

Answered by Theo Tsihitas on December 19, 2020

Add your own answers!

Related Questions

Ubuntu emulator not boot up with fglrx

0  Asked on October 31, 2021 by inglebard


Unable to process upgrades due to error with snmpd

1  Asked on October 31, 2021 by malchesador


apache2 welcome page not showing

1  Asked on October 31, 2021


command ‘go’ not found

5  Asked on October 31, 2021


a2dp-sink profile connect failed

5  Asked on October 31, 2021 by keddad


Only “Dummy output” (sound) in Ubuntu 20.04 after reboot – Broken driver / module

8  Asked on October 31, 2021 by sancho-s-reinstatemonicacellio


arrow/exclamation symbol on top bar

1  Asked on October 31, 2021


Samsung printer m2070 no working on ubuntu

1  Asked on October 31, 2021 by vladimir-usora


Wine in Ubuntu cannot create temporary directory error?

0  Asked on October 31, 2021 by aman-grover


Malformed security header

1  Asked on October 31, 2021 by mh-shuvo


Evince shows small frame in Presentation mode

2  Asked on October 31, 2021 by popoolmica


Keyboard Stops working after flashing not allowed sign

0  Asked on October 31, 2021 by piyush-sharma


Can’t get 4k @ 60hz, only 30hz

2  Asked on October 31, 2021 by tumdum


Clamav – OnAccessMountPath & OnAccessPrevention

0  Asked on October 31, 2021 by polik989


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP