1

I like to use middle mouse button emulation, because my middle mouse button is a scroll wheel and it takes a lot of pressure to register a click. This gets physically painful pretty quickly.

I find it much easier to just click the left and right mouse buttons simultaneously. And I use this feature all the time.

I have a script in ~/scripts/mouse.sh that does this:

#!/bin/bash

# Enable middle button emulation
# from https://askubuntu.com/a/201825/54278
if [[ -n ${DISPLAY} ]]; then
    pointer1="MX Master"
    id1=$(xinput | awk -F= "/$pointer1.*pointer/ {print \$2}" | cut -f1)
    xinput set-prop "${id1}" "libinput Middle Emulation Enabled" 1
fi

This works well, but I have to run it manually every time I reboot.

I've created ~/.config/autostart/mouse.sh.desktop. These are the contents:

[Desktop Entry]
Type=Application
Exec=/home/david/.scripts/mouse.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_AU]=Mouse
Name=Mouse
Comment[en_AU]=Middle button emulation
Comment=Middle button emulation

My problem is that my script doesn't do anything on login.

I still have to open a terminal and run my script before middle mouse button emulation works.

I've tried removing the if [[ -n ${DISPLAY} ]]; then condition, and I've tried adding a sleep at the start of the script.

I've also tried adding the contents of my script to ~/.profile.

None of these things have worked. This has been bugging me for years!

Thanks for having a look :-)


Edits

  1. Also tried Exec=/bin/bash /home/david/.scripts/mouse.sh. Thanks @PRATAP
  2. Ubuntu 19.04, though it also hasn't worked in the last few versions, including 18.04
  3. Tried deleting the .desktop file and using the Startup Applications GUI
  4. Tried removing the if [[ -n ${DISPLAY} ]]; then condition
  5. I had a flash of inspiration and tried using Exec=/usr/bin/xterm -e /home/david/.scripts/mouse.sh - also no luck

1 Answers1

1

The thing worked for me is the below script

/home/user/mouse.sh

#!/bin/bash

    pointer1="Logitech USB Receiver Mouse"
    id1=$(xinput | awk -F= "/$pointer1.*pointer/ {print \$2}" | cut -f1)
    xinput set-prop "${id1}" "libinput Middle Emulation Enabled" 1

some of the Output of xinput

$ xinput
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ETPS/2 Elantech Touchpad                  id=11   [slave  pointer  (2)]
⎜   ↳ Logitech USB Receiver Consumer Control    id=16   [slave  pointer  (2)]
⎜   ↳ Logitech USB Receiver Mouse               id=18   [slave  pointer  (2)]

and added the command /bin/bash /home/user/mouse.sh in Startup Applications Preferences..

enter image description here