https://askubuntu.com/questions/824593/udev-rule-for-external-mouse-detection-to-turn-touchpad-on-and-off
xinput list
find the name of touchpad
- create the toggle script
NAMEOFSCRIPT.SH
#!/bin/sh
#
# Enables the touchpad if and only if there aren't any external mice connected.
#
# Originally from:
# https://wiki.archlinux.org/index.php/Touchpad_Synaptics#System_with_multiple_X_sessions
# This supports also ALPS touchpads.
#Here puts how is named (Run 'xinput list' for the name to put below)
TOUCHPAD="HAILUCK CO.,LTD USB KEYBOARD Mouse"
FOUND=0
for MOUSE in `find /sys/class/input -name mouse\*`
do
if [ "`cat $MOUSE/device/name`" != "$TOUCHPAD" ]
then
FOUND=1
#Find a Mouse device other than the TouchPad and record the variable.
break
fi
done
DISPLAY=:0
export DISPLAY
for USER in `w -h | cut -d\ -f1 | sort | uniq`
do
XAUTHORITY=`sudo -Hiu $USER env | grep ^HOME= | cut -d= -f2`/.Xauthority
export XAUTHORITY
TOUCHPADDEVICE=$(($(xinput list | grep -i "$TOUCHPAD" | cut -d= -f2 | cut -d[ -f1)+0))
#Find the Touchpad Id
if [ $FOUND -eq 1 ]; then
#If another device is founded, disable touchpad
xinput disable $TOUCHPADDEVICE
else
#else enable touchpad
xinput enable $TOUCHPADDEVICE
fi
done
- create UDEV rule file
/etc/udev/rules.d/01-touchpad_toggle.rules
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**"