This question already has an answer here:

I do not have function key / fn for that :( .

Any ideas? Maybe there are settings or commands?


Other subjects were NOT helpful:

  • gpointing-device-settings (auto-disable setting gets unticked);
  • kde-config-touchpad (can not be installed alone);
  • no idea how to useudevd .

marked as duplicate by Esamo, Eliah Kagan, Eric Carvalho, Zanna, Fabby Apr 27 at 20:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Solution - automatic

Thanks to Esamo and his work.

To add AUTO triggers for connecting mouse on startup:

Create the file: /etc/udev/rules.d/10-local.rules

Fill up with this content: (replace $USER with your user name)

ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh false"

ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh true"

Example:

ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh false"

ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh true"

Next place your script wherever you want. I placed it in ~/scripts

touchpad_switcher.sh

#!/bin/sh
enabled=$1
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);

if $enabled
then
  xinput set-prop $touchpad_id "Device Enabled" 1 | notify-send "The touchpad is now enabled." ""
else
  xinput set-prop $touchpad_id "Device Enabled" 0 | notify-send "Disabling the touchpad..." ""
fi

Remember to add execute permissions:

chmod +x touchpad_switcher.sh

Now simply reboot! ( merely restarting udev doesn't seem to work...)


Some other useful stuff:

Some info about udev rules

Example from ArchLinux

Simlar question

  • @Dawid Drozd Thanks for this answer for an important feature. Unfortunately it does not seem to fully work on my laptop with Ubuntu 14.04. The notifications are shown (disabled, enabled) when the mouse is plugged in and out, but the touchpad continues to be enabled. Any tip? – Filbuntu Aug 1 '15 at 2:16
  • @Filbuntu maybe can't find the right id? Try xinput and if your touchpad device doesn't have "touchpad" on it, that's the problem. – Iazel Aug 7 '15 at 14:10
  • @lazel Thanks for the answer! xinputshows a touchpad: Virtual core pointer id=2 [master pointer (3)] ⎜ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ VGeneric USB K/B id=11 [slave pointer (2)] ⎜ V SIGMACHIP Usb Mouse id=12 [slave pointer (2)] ⎜ DLL0641:00 06CB:7621 UNKNOWN id=14 [slave pointer (2)] ⎜ **SynPS/2 Synaptics TouchPad** id=16 [slave pointer (2)] - Any further tip? – Filbuntu Aug 8 '15 at 1:28
up vote 5 down vote accepted

SOLUTION - not automatic

The script below, when executed, will disable the touchpad if any mouse is connected and show a notification.

touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);


if xinput | grep -i "mouse" | grep -i "pointer"

    then xinput set-prop $touchpad_id "Device Enabled" 0 |
         notify-send "Disabling the touchpad..." ""

    else xinput set-prop $touchpad_id "Device Enabled" 1 |
         notify-send "The touchpad is now enabled." ""

fi

Added there also a reverse situation, although in my case the touchpad gets enabled on mouse disconnection anyway. I have saved the script in a file and am running it from Unity Launcher Terminal section after every mouse plug in.


ADVANCED

  1. More mouses?

    Clarify which mouse should deactivate the touchpad by expanding the value in "mouse" fragment, name based on xinput devices list.

  2. Scared mouse runs from edge to edge?

    I had to run additional command for mouse - decreasing cursor acceleration since it is madly set to 10 on every connection. Actually after a while I made auto-detection script (it gets mouse id and its' prop for velocity; dunno about performance of cut)...

    touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
    mouse_id=$(xinput | grep -i "mouse" | grep -i 'pointer' | cut -f2 | cut -d '=' -f2);
    mouse_prop=$(xinput list-props $mouse_id | grep -i "velocity" | cut -f2 | cut -d '(' -f2 | cut -d ')' -f1 );
    
    
    if xinput | grep -i "mouse" | grep -i "pointer"
    
        then xinput set-prop $touchpad_id "Device Enabled" 0 |
             xinput set-prop $mouse_id $mouse_prop 3 |
             notify-send "Disabling the touchpad..." ""
    
        else xinput set-prop $touchpad_id "Device Enabled" 1 |
             notify-send "The touchpad is now enabled." ""
    
    fi
    

Learned a lot today to make above :D .


SOMEONE PRO?

  1. Would be useful to know how to make it automatic.

  2. Also curious why mouse config is not saved (2.).

What @David Drozd posted didn't work for me on Ubuntu 16.04.

Seems like the trick with xinput don't work in udev. Only synclient TouchpadOff=[0|1] worked. Also ACTION="remove" didn't work solely.

I finally got it when added ENV{REMOVE_CMD}="/bin/sh -c '/usr/bin/synclient TouchpadOff=0'"

The full solution: create the file /etc/udev/rules.d/10-local.rules with the following line (replace $USER with your user name)

ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{REMOVE_CMD}="/bin/sh -c '/usr/bin/synclient TouchpadOff=0'", RUN+="/bin/sh -c '/usr/bin/synclient TouchpadOff=1' "

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