# How to disable touchpad when mouse is connected and how to rebind mouse buttons?

**URL:** <https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784>\
**Category:** Newbie\
**Created:** [May 3, 2024, 4:34pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784 "2024-05-03T16:34:53Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 3, 2024, 4:34pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/1 "2024-05-03T16:34:53Z")

</div>

Hello,

I would like my laptop’s touchpad to get disabled when I connect a mouse. I have seen an option like this on Mint with Cinnamon, but I can’t find anything like it in Endeavour with Plasma.

Also, my mouse has two side buttons for navigating forwards and backwards in browsers and such, but I would like to swap the buttons. I have found the “Re-bind additional mouse buttons” option in mouse settings, but it doesn’t look like it can be used to achieve what I need.

I have searched around, but most solutions were for Xorg and non-Arch distros. Does anyone have any advice, please?

---

<div class="post-metadata">

**Author:** ![eso](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/eso/32/36767_2.png) [@eso](https://forum.endeavouros.com/u/eso)\
**Post date:** [May 3, 2024, 8:59pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/2 "2024-05-03T20:59:00Z")

</div>

Hello @bytehowl ,  
Not all of your questions I’m going to answer.

```auto
yay -S ydotool
sudo systemctl daemon-reload
sudo systemctl enable ydotool.service
sudo systemctl start ydotool.service
ydotool key 530:1 530:0

```

This last command toggles touchpad enable.

`yay -S wayland-mouse-mapper-git`  
From now on your creativity is needed. I haven’t tested this (edit it)  
`/usr/bin/mousemapper`  
To understand [more or to get lost](https://www.baeldung.com/linux/mouse-events-input-event-interface)

[The mousemapper script is almost the same here.](https://github.com/mathportillo/wayland-mouse-mapper)  
Edit 1:  
Here is a more promising clue:

```auto
yay input-remapper
sudo systemctl enable --now input-remapper
sudo systemctl start --now input-remapper

```

```auto
sudo input-remapper-control --list-devices | grep Mouse > /tmp/mouse
if [[-s /tmp/mouse]]; then
   ydotool key 530:1 530:0
fi

```

to check if mouse is present  
and  
`input-remapper-gtk`  
helps you to do the remapping

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 4, 2024, 11:34am UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/3 "2024-05-04T11:34:11Z")

</div>

Hm, so I take your advice to mean there’s no built-in way to achieve what I need?

Ydotools isn’t working for me, when I get to the step to enable the service I get:

```
Failed to enable unit: Unit file ydotool.service does not exist.

```

This happens even after restart.

I have taken a look at the mousemapper script and read the Baeldung page. At a glance it looks like it should work, but I’m not good enough at bash to fully understand the script. I’ll need to take some time to sit down and take a proper look at it.

I have also taken a look at the input-remapper and I was able to remap the buttons on the mouse. I think a utility like this is preferable for me compared to scripting. I wasn’t able to make it turn off the touchpad yet, because of the ydotools issue…

---

<div class="post-metadata">

**Author:** ![anon31549144](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@anon31549144](https://forum.endeavouros.com/u/anon31549144)\
**Post date:** [May 4, 2024, 11:38am UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/4 "2024-05-04T11:38:23Z")

</div>

No idea about this specific solution, but have you tried `sudo systemctl enable ydotool` ? as a quick attempt to make this work?

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 4, 2024, 11:41am UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/5 "2024-05-04T11:41:46Z")

</div>

> [@anon31549144](#):
>
> No idea about this specific solution, but have you tried `sudo systemctl enable ydotool` ? as a quick attempt to make this work?

I have tried that version and it didn’t work either.

---

<div class="post-metadata">

**Author:** ![xircon](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/xircon/32/9124_2.png) [@xircon](https://forum.endeavouros.com/u/xircon)\
**Post date:** [May 4, 2024, 1:00pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/6 "2024-05-04T13:00:16Z")

</div>

> [@anon31549144](#):
>
> sudo systemctl enable ydotool

```auto
systemctl enable ydotool.service --user --now  

```

---

<div class="post-metadata">

**Author:** ![eso](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/eso/32/36767_2.png) [@eso](https://forum.endeavouros.com/u/eso)\
**Post date:** [May 4, 2024, 3:23pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/7 "2024-05-04T15:23:09Z")

</div>

@bytehowl  
Sorry, RE ydotool I forgot something.

```auto
su
kate /usr/lib/systemd/system/ydotool.service

```

```auto
[Unit]
Description=Starts ydotoold service

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/ydotoold --socket-path="/run/user/1000/.ydotool_socket" --socket-own="1000:1000"
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=process
TimeoutSec=180

[Install]
WantedBy=default.target

```

`exit` and then

```auto
systemctl daemon-reload
systemctl --user enable ydotool.service
systemctl --user start ydotool.service
ydotool key 530:1 530:0

```

---

<div class="post-metadata">

**Author:** ![anon31549144](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@anon31549144](https://forum.endeavouros.com/u/anon31549144)\
**Post date:** [May 4, 2024, 3:33pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/8 "2024-05-04T15:33:58Z")

</div>

Works without the .service. Try it out 😉

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 4, 2024, 5:46pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/9 "2024-05-04T17:46:14Z")

</div>

> [@xircon](#):
>
> > [@anon31549144](#):
> >
> > sudo systemctl enable ydotool
> 
> `systemctl enable ydotool.service --user --now `

```
Failed to connect to bus: No medium found

```

> [@eso](#):
>
> ```auto
> [Unit]
> Description=Starts ydotoold service
> 
> [Service]
> Type=simple
> Restart=always
> ExecStart=/usr/bin/ydotoold --socket-path="/run/user/1000/.ydotool_socket" --socket-own="1000:1000"
> ExecReload=/usr/bin/kill -HUP $MAINPID
> KillMode=process
> TimeoutSec=180
> 
> [Install]
> WantedBy=default.target
> 
> ```
> 
> `exit` and then
> 
> ```auto
> systemctl daemon-reload
> systemctl --user enable ydotool.service
> systemctl --user start ydotool.service
> ydotool key 530:1 530:0
> 
> ```

I got all the way to the end, and then:

```
failed to connect socket `/run/user/1000/.ydotool_socket': No such file or directory
Please check if ydotoold is running.

```

---

<div class="post-metadata">

**Author:** ![eso](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/eso/32/36767_2.png) [@eso](https://forum.endeavouros.com/u/eso)\
**Post date:** [May 4, 2024, 9:51pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/10 "2024-05-04T21:51:17Z")

</div>

It’s not exclusively my fault this ambiguity around ydotool configuration. Here is a summary

```auto
yay ydotool
sudo chmod +s $(which ydotool) # all users can use it

```

```auto
# ~/.bashrc
#
export YDOTOOL_SOCKET="/tmp/.ydotool_socket"

```

`mkdir -p .config/systemd/user/`  
`kate ~/.config/systemd/user/ydotoold.service`

```auto
[Unit]
Description=Starts ydotoold service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=3
ExecStart=/usr/bin/ydotoold --socket-path="/tmp/.ydotool_socket"
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=process
TimeoutSec=180

[Install]
WantedBy=default.target

```

`sudo cp /home/a/.config/systemd/user/ydotoold.service /usr/lib/systemd/system/ydotoold.service`  
#a is my user name

```auto
sudo systemctl daemon-reload
sudo systemctl enable ydotoold
sudo systemctl start ydotoold

```

logout, login `ps -ef | grep ydotool` should show bg proc  
`ydotool key 530:1 530:0` # toggles touchpad in wayland

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 6, 2024, 6:43pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/11 "2024-05-06T18:43:58Z")

</div>

> [@eso](#):
>
> It’s not exclusively my fault this ambiguity around ydotool configuration. Here is a summary
> 
> ```auto
> yay ydotool
> sudo chmod +s $(which ydotool) # all users can use it
> 
> ```
> 
> ```auto
> # ~/.bashrc
> #
> export YDOTOOL_SOCKET="/tmp/.ydotool_socket"
> 
> ```
> 
> `mkdir -p .config/systemd/user/`  
> `kate ~/.config/systemd/user/ydotoold.service`
> 
> ```auto
> [Unit]
> Description=Starts ydotoold service
> StartLimitIntervalSec=0
> 
> [Service]
> Type=simple
> Restart=always
> RestartSec=3
> ExecStart=/usr/bin/ydotoold --socket-path="/tmp/.ydotool_socket"
> ExecReload=/usr/bin/kill -HUP $MAINPID
> KillMode=process
> TimeoutSec=180
> 
> [Install]
> WantedBy=default.target
> 
> ```
> 
> `sudo cp /home/a/.config/systemd/user/ydotoold.service /usr/lib/systemd/system/ydotoold.service`  
> #a is my user name
> 
> ```auto
> sudo systemctl daemon-reload
> sudo systemctl enable ydotoold
> sudo systemctl start ydotoold
> 
> ```
> 
> logout, login `ps -ef | grep ydotool` should show bg proc  
> `ydotool key 530:1 530:0` # toggles touchpad in wayland

Okay, that finally did it, but there’s another problem…

> [@eso](#):
>
> ```auto
> sudo input-remapper-control --list-devices | grep Mouse > /tmp/mouse
> if [[-s /tmp/mouse]]; then
> ydotool key 530:1 530:0
> fi
> 
> ```

My touchpad is listed as “ELAN0501:00 04F3:3060 Mouse”, so that script would create the mouse tmp file even if I just have my touchpad.

Also, where am I supposed to put that script so it gets run when devices are (dis)connected?

---

<div class="post-metadata">

**Author:** ![eso](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/eso/32/36767_2.png) [@eso](https://forum.endeavouros.com/u/eso)\
**Post date:** [May 7, 2024, 12:09am UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/12 "2024-05-07T00:09:32Z")

</div>

@bytehowl  
Here is a ‘recalculated’ version (skip to Edit2):

```auto
#!/bin/sh
journalctl -f -p 6 | awk '/idVendor=046d|disconnect/ { system ("ydotool key 530:1 530:0") }'

```

find a unique string in journal when your mouse is plugged in /switched on and disconnected by this command:  
`journalctl -f -p 6`  
The customized script may be autostarted.  
Static query is below at Edit2  
It seems a bit over-engineered.

Edit2  
For me the RTFM is pretty valid.  
`/usr/include/linux/input-event-codes.h`  
So having configured ydotool we also have touchpad on (531) and off (532) keycodes. Let’s wipe down the ‘white-board’ and simplify the case.  
I inserted 2 scripts into Autostart a login and a logout one  
cat momp.sh

```auto
#!/bin/sh
# Check whether mouse is plugged-in and disable/enable touchpad
while :
do
    lsusb | grep -q Mouse
    MOUSE="$?"
    if ["$MOUSE" != "$PREM"]; then
     case $MOUSE in
      0)
       ydotool key 532:1 532:0
       ;;
      1)
       ydotool key 531:1 531:0
       ;;
     esac
     PREM="$MOUSE"
   fi
    sleep 5
done

```

and before logout:

cat mompend.sh

```auto
#!/bin/sh
pkill momp.sh

```

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 7, 2024, 9:54pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/13 "2024-05-07T21:54:01Z")

</div>

> [@eso](#):
>
> ```auto
> #!/bin/sh
> # Check whether mouse is plugged-in and disable/enable touchpad
> while :
> do
> lsusb | grep -q Mouse
> MOUSE="$?"
> if ["$MOUSE" != "$PREM"]; then
> case $MOUSE in
> 0)
> ydotool key 532:1 532:0
> ;;
> 1)
> ydotool key 531:1 531:0
> ;;
> esac
> PREM="$MOUSE"
> fi
> sleep 5
> done
> 
> ```
> 
> and before logout:
> 
> cat mompend.sh
> 
> ```auto
> #!/bin/sh
> pkill momp.sh
> 
> ```

OK, so the final script does work. It is just unfortunate that it relies on a unique string relevant to each device - I don’t always use the same mouse, even now I have a different one than when I started this thread. I suppose I could just check the `lsusb` output against an array of identifiers… Ideally, it would be built-in, but I guess that’s a complaint for the Plasma devs.

That being said I think can make do with this solution for now. Thank you for your help and patience 🙂

---

<div class="post-metadata">

**Author:** ![eso](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/eso/32/36767_2.png) [@eso](https://forum.endeavouros.com/u/eso)\
**Post date:** [May 8, 2024, 8:05am UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/14 "2024-05-08T08:05:31Z")

</div>

> [@eso](#):
>
> ` lsusb | grep -q Mouse`

@bytehowl Extended grep covers all of your mice

> lsusb | grep -q -E -w ‘Mouse|trackball|anything’

BTW did you @bytehowl know that touchpad can be enabled/disabled by by assigning shortcuts out of the box. Never mind otherwise I would not have learned some new scripting stuff.

---

<div class="post-metadata">

**Author:** ![bkaplan](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/bkaplan/32/5979_2.png) [@bkaplan](https://forum.endeavouros.com/u/bkaplan)\
**Post date:** [May 8, 2024, 9:08pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/15 "2024-05-08T21:08:19Z")

</div>

Just did this very easily and successfully on my wife’s laptop. In plasma, go to system settings \> mouse & touchpad \> touchpad. There are checkboxes for disabling the device entirely (if you always use the external mouse, which she does) and disable while typing. Check/ uncheck as you choose. You will need to reboot (not just logout) for the changes to take effect

---

<div class="post-metadata">

**Author:** ![bytehowl](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@bytehowl](https://forum.endeavouros.com/u/bytehowl)\
**Post date:** [May 8, 2024, 9:25pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/16 "2024-05-08T21:25:44Z")

</div>

> [@eso](#):
>
> BTW did you @bytehowl know that touchpad can be enabled/disabled by by assigning shortcuts out of the box. Never mind otherwise I would not have learned some new scripting stuff.

I do, in fact I didn’t even need to assign anything, the Fn+F7 on my laptop works. However, I’m used to having this automated, and as I have mentioned earlier, Cinnamon has this and also Gnome (with a bit of digging).

> [@bkaplan](#):
>
> Just did this very easily and successfully on my wife’s laptop. In plasma, go to system settings \> mouse & touchpad \> touchpad. There are checkboxes for disabling the device entirely (if you always use the external mouse, which she does) and disable while typing. Check/ uncheck as you choose. You will need to reboot (not just logout) for the changes to take effect

Reboots shouldn’t actually be necessary, but again, not automated.

---

<div class="post-metadata">

**Author:** ![system](https://forum.endeavouros.com/uploads/default/original/2X/9/9ea52f9fd5ef8e609e593c362d61a36295f48be8.png) [@system](https://forum.endeavouros.com/u/system)\
**Post date:** [May 10, 2024, 9:26pm UTC](https://forum.endeavouros.com/t/how-to-disable-touchpad-when-mouse-is-connected-and-how-to-rebind-mouse-buttons/54784/17 "2024-05-10T21:26:34Z")

</div>

Closed on May 10, 2024, 9:26pm UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
