Skip to content

Instantly share code, notes, and snippets.

@ysim
Last active April 16, 2022 21:14
Show Gist options
  • Save ysim/f9f97be39c024f65bc4814128249c9f5 to your computer and use it in GitHub Desktop.
Save ysim/f9f97be39c024f65bc4814128249c9f5 to your computer and use it in GitHub Desktop.
Toggle touchpad on/off on Ubuntu

Toggle the touchpad on/off with a keyboard shortcut on Ubuntu 16.04

The keyboard on the Dell XPS is far too sensitive and I would prefer for the touchpad to be disabled while a mouse is plugged in.

Instructions

  1. In the Terminal, determine the device number that corresponds to your touchpad by running:

     xinput
    

    For instance, this is the output I get on my laptop:

     $ xinput
     ⎡ Virtual core pointer                          id=2    [master pointer  (3)]
     ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
     ⎜   ↳ SteelSeries Kana Gaming Mouse             id=10   [slave  pointer  (2)]
     ⎜   ↳ DLL075B:01 06CB:76AF Touchpad             id=12   [slave  pointer  (2)]
     ⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
         ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
         ↳ Power Button                              id=6    [slave  keyboard (3)]
         ↳ Video Bus                                 id=7    [slave  keyboard (3)]
         ↳ Power Button                              id=8    [slave  keyboard (3)]
         ↳ Sleep Button                              id=9    [slave  keyboard (3)]
         ↳ Integrated_Webcam_HD                      id=11   [slave  keyboard (3)]
         ↳ Intel Virtual Button driver               id=13   [slave  keyboard (3)]
         ↳ Intel HID events                          id=14   [slave  keyboard (3)]
         ↳ AT Translated Set 2 keyboard              id=15   [slave  keyboard (3)]
         ↳ Dell WMI hotkeys                          id=17   [slave  keyboard (3)]
    

    So my device number is 12.

  2. Copy toggle-touchpad somewhere on your $PATH and make it executable.

  3. Replace the device_number variable in toggle-touchpad as appropriate.

  4. Under System Settings > Keyboard > Shortcuts > Custom Shortcuts, create a new shortcut, name it (e.g. "Toggle touchpad on/off"), and set the command to toggle-touchpad. I set the shortcut to Super-Z on mine (Super refers to the Windows key).

  5. Now you can hit Super-Z to toggle the touchpad on/off.

References

#!/bin/bash
# This is the device number matching touchpad
# Determine the device number by running `xinput`
device_number=12
# Determine the state (0 for disabled, 1 for enabled)
state="$(xinput list-props "${device_number}" | grep "Device Enabled" | grep -o "[01]$")"
if [[ "${state}" == '0' ]]; the
xinput --enable "${device_number}"
DISPLAY=:0 notify-send --urgency=low "Touchpad enabled"
else
xinput --disable "${device_number}"
DISPLAY=:0 notify-send --urgency=low "Touchpad disabled"
fi
exit 0
@NylQa
Copy link

NylQa commented Apr 16, 2022

Line 10 - lost the letter "n" in the word "then".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment