Toggle Your Laptop's Trackpad/Touchpad On and Off

Enable toggling the touchpad on and off with a hardware key

Most laptop computers these days use a touch-enabled device in place of an external mouse. Given that the built-in "disable touchpad while typing" feature does not work for some people, having the ability to manually disable the touch-enabled device can prevent typing mistakes. Many computer manufacturers provide a function key or key combination that alternately enables and disables the device. The device might be called "trackpad", "touchpad", "clickpad", or something similar. I'll use the term "touchpad" here. Just be aware that your device may have a different name or may be referenced by its commercial brand name on your hardware.

Sometimes the specific touch-enabled device you have and which distribution of Linux you use will determine what command you will need to use in your script. For Ubuntu MATE 17.10 and Ubuntu MATE 18.04 and the "touchpad" provided on the Dell XPS 13, the command xinput is what we need to use.

The steps I used are these:

  1. Determine the name of the touchpad using this command.
    xinput list
    Mine is listed as "DLL075B:01 06CB:76AF Touchpad."
  2. Test whether you can disable the touchpad. In my case, the command is
    xinput disable "DLL075B:01 06CB:76AF Touchpad"
    This successfully turned the touchpad off.
  3. Test that the touchpad can be re-enabled.
    xinput enable "DLL075B:01 06CB:76AF Touchpad"
    This worked, too!
  4. Write the script using what I've learned. Below is the script I created. I named the file, "toggle-touchpad.sh" and put it in the folder ~/bin. The first line of the script determines whether the touchpad is enabled or disabled. The lines that start with the notify-send command display a confirmation message on the screen.

Script for Dell XPS 13 Notebook

#!/bin/sh
# toggle-touchpad script
#
# Toggles the touchpad on and off. Bind this script to a key to turn on and off
# your touchpad/trackpad. The F7 key is a good choice on the XPS13.

# This is the version for Ubuntu MATE on the Dell XPS13 9360
# ##########################################################
# Larry Bushey
#
if [ $(xinput list-props "DLL075B:01 06CB:76AF Touchpad" | grep 'Device Enabled' | gawk -F ': ' '{ print $2 }') -eq 0 ]; then
xinput enable "DLL075B:01 06CB:76AF Touchpad"
notify-send --icon=/usr/share/icons/mate/scalable/actions/touchpad-enabled.svg "Enabled" "Your computer's touchpad is enabled."
else
xinput disable "DLL075B:01 06CB:76AF Touchpad"
notify-send --icon=/usr/share/icons/mate/scalable/actions/touchpad-disabled.svg "Disabled" "Your computer's touchpad is disabled."
fi


Script for HP G60 Notebook

#!/bin/sh
# toggle-touchpad script
#
# Toggles the touchpad on and off. Bind this script to a button to turn on and off
# your touchpad/trackpad. The hardware button above the HP G60's touchpad is a great choice.

# This is the version for Ubuntu MATE on the HP G60-230US
# #######################################################
# Larry Bushey
#
if [ $(xinput list-props "SynPS/2 Synaptics TouchPad" | grep 'Device Enabled' | gawk -F ': ' '{ print $2 }') -eq 0 ]; then
xinput enable "SynPS/2 Synaptics TouchPad"
notify-send --icon=/usr/share/icons/mate/scalable/actions/touchpad-enabled.svg "Enabled" "Your computer's touchpad is enabled."
else
xinput disable "SynPS/2 Synaptics TouchPad"
notify-send --icon=/usr/share/icons/mate/scalable/actions/touchpad-disabled.svg "Disabled" "Your computer's touchpad is disabled."
fi


Now it's time to test the script by running it from the terminal. Make sure it alternately enables and disables the touchpad each time it is run. (You may find that you need to install the "gawk" utility from your software repository.)

Finally, we assign the desired function key or key combination to the script. In my case, I chose the F7 key on the XPS 13.

  1. Open the Control Center (Menu > Control Center) and select Keyboard Shortcuts.
  2. Click the Add button to create a new custom keyboard shortcut.
  3. In the Name field, type "Toggle Touchpad".
  4. In the Command field, if you placed the script in the recommended folder, simply type the name of the script, including the ".sh" extension, otherwise you will need to type the entire path.
    Dialog box for creating a shortcut
  5. Click the Apply button to save the settings.
  6. To assign a function key or other hardware key, in the list of custom shortcuts, locate the Toggle Touchpad shortcut and double-click on the words "New Shortcut..." and then press the key or key combination you want use to activate the shortcut.
    The new shortcut on the XPS 13

Note: If you are using a function key, this will work as described. On my older HP G60, a hardware button is supplied just above the Touchpad. When the Touchpad is enabled, the button press registers as a "TouchpadOff" action. When the Touchpad is disabled, the button lights up with an orange LED and when pressed the button press registers as a "TouchpadOn" action

Now it's time to test the script by running it from the terminal. Make sure it alternately enables and disables the touchpad each timit registers as a "TouchpadOn" action. I created two entries using the same toggle-touchpad.sh script, one to enable and one to disable. See the screen shot, below.

Two custom shortcuts on the HP G60

More reading

The script above or a modification of it will likely work for you. If it doesn't, here are a couple of options that might lead you in the right direction for your combination of hardware and software.

This community post is an alternative that works with Ubuntu MATE 16.04 and the "touchpad" provided on an Entroware Orion laptop. https://ubuntu-mate.community/t/keyboard-shortcut-for-touchpad/12114

This wiki post provides a method that works when using a Gnome 3.x desktop on a computer with a Synaptics Touchpad.  https://wiki.archlinux.org/index.php/Touchpad_Synaptics