Pawel Zadrozny


About confusing or poorly documented features of tools and libraries I use.

Toggle TouchPad shortcut

21 Feb 2018 tools | #shell #ubuntu #linux

On my MSI laptop I was able to enable and disable touchpad with fn + F3 shortcut. It is not the case anymore. Default shortcut has stop working some day without any warning.

I found a thread on Ask Ubuntu which helped me with my issue. All credits goes to wineunuuchs2unix, thank You very much for contribution to community.

I’ve made slight modification to increase readability. I’ve changed urgency level and icons to those which can be found in Ubuntu 17.10.

First of all check TouchPad ID on your machine.

$ xinput list | grep -i touchpad
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=15	[slave  pointer  (2)]

It appears that on my machine TouchPad has id=15.

Create new shell script.

$ sudo vim /usr/bin/toggle-touchpad

Copy and paste below script, and change xinput_id=15 to ID of TouchPad on your machine. Touchpad icons are available on Ubuntu 17. You can use any images from any directory.


# NAME: toggle-touchpad
# PATH: /usr/bin
# DESC: Update pulseaudio output device when HDMI TV plugged / unplugged
# CALL: called from Keyboard Shortcut `Super`+`T`
# DATE: Created Dec 23, 2016.
# NOTE: Originaly written for AU question:
# COPYRIGHT: WinEunuuchs2Unix, Pawelzny

xinput_id=15  # This ID may differ for every machine.

if [[ $(xinput list $xinput_id | grep -Ec "disabled") -eq 1 ]]; then
    xinput enable $xinput_id
    DISPLAY=:0 notify-send \
               --urgency=normal \
               --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png \
               "Touchpad enabled"
    xinput disable $xinput_id
    DISPLAY=:0 notify-send \
               --urgency=normal \
               --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png \
               "Touchpad disabled"
exit 0

Make the script executable.

$ sudo chmod a+x /usr/bin/toggle-touchpad

Go to settings –> devices –> keyboard and create custom shortcut Super+T for /usr/bin/toggle-touchpad script.

Screenshot of Ubuntu keyboard shortucts settings @pawelzny