Skip to content

Instantly share code, notes, and snippets.

@iamkissg
Created March 31, 2017 13:02
Show Gist options
  • Save iamkissg/50513b294c65dd20a82a807a85b58f7a to your computer and use it in GitHub Desktop.
Save iamkissg/50513b294c65dd20a82a807a85b58f7a to your computer and use it in GitHub Desktop.
Toggle touchpad (enable/disable) in Linux with xinput.
#!/bin/bash
#
# type cmd `xinput`, it shows my device X input information as follow
#
# ➜ ~ xinput
# ⎡ Virtual core pointer id=2 [master pointer (3)]
# ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
# ⎜ ↳ ETPS/2 Elantech Touchpad id=14 [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)]
# ↳ Asus Wireless Radio Control id=7 [slave keyboard (3)]
# ↳ Video Bus id=8 [slave keyboard (3)]
# ↳ Video Bus id=9 [slave keyboard (3)]
# ↳ Sleep Button id=10 [slave keyboard (3)]
# ↳ ASUS USB2.0 Webcam id=11 [slave keyboard (3)]
# ↳ Asus WMI hotkeys id=12 [slave keyboard (3)]
# ↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
#
# So my touchpad's ID is 14, then use `xinput disable 14` and `xinput enable 14` for toggling~
#
# Following bash script is referred to this askubuntu question:
# http://askubuntu.com/questions/751413/how-to-disable-enable-toggle-touchpad-in-a-dell-laptop
if xinput list-props 14 | grep "Device Enabled (169):.*1" >/dev/null
then
xinput disable 14
notify-send -u low -i mouse "Trackpad disabled"
else
xinput enable 14
notify-send -u low -i mouse "Trackpad enabled"
fi
@VirtDev337
Copy link

I am having the issue of the touchpad function keys to toggle not working on my asus tuf a17 in Zorin OS 15. I followed your recommendation, and wrote this up as a script under /etc/acpi with a trigger from /etc/acpi/events with the following lines:

event=0B3CBB35-E3C2- 000000ff 00000000
action=/etc/apci/elan-touchpad.sh

the event is the key combination of the function and F10 keys.
my elan-touchpad.sh has the following:

#!/bin/sh

if xinput list-props 17 | grep "Device Enabled (156):.*1" >/dev/null
then
xinput disable 17
notify-send -u low -i mouse "Trackpad disabled"
else
xinput enable 17
notify-send -u low -i mouse "Trackpad enabled"
fi

but the shortcut still does not provide function. I use an external mouse and having this ability to switch between the two by shortcut would be beneficial. Any help you could provide would be appreciated.

@rimutaka
Copy link

A more robust version would be this one-liner that you can bind to a key in settings:

if xinput list-props 15 | grep "Device Enabled ([[:digit:]]\+):\s*1" >/dev/null; then xinput disable 15 && notify-send -u low -i mouse "Trackpad disabled"; else xinput enable 15 && notify-send -u low -i mouse "Trackpad enabled"; fi

Replace the device ID (15) with the one specific to your system. Note, it may change if systems id reconfigured.

@yamirui
Copy link

yamirui commented Jul 27, 2022

@rimutaka thanks for making it one line for no reason to make it harder to read.

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