How to disable/enable/toggle touchpad in a Dell laptop
You can switch the touchpad off with this command:
xinput disable 13
Enable it back by
xinput enable 13
The device is not controlled by psmouse
. It is controlled by synaptics_i2c
. And it is device 13.
You can also toggle it by name as you tried before, not to depend on the ID. But if you do not connect new input devices, the ID should stay.
See this answer for some details.
To remove a wrongly detected device you need to add i8042.nopnp
kernel boot parameter.
Using gsettings
If you can change settings by gsettings
, generally it is the preferred option. Since you can enable/disable touchpad from System Settings, and I am pretty sure System Settings does use gsettings
, it looks like the method below should do the job, on your Dell as well.
Script to toggle the touchpad
14.04
#!/usr/bin/env python3
import subprocess
key = "org.gnome.settings-daemon.peripherals.touchpad" ;val = "touchpad-enabled"
curr = subprocess.check_output(["gsettings", "get", key, val]).decode("utf-8").strip()
newval = "false" if curr == "true" else "true"
subprocess.Popen(["gsettings", "set", key, val, newval])
15.04+
#!/usr/bin/env python3
import subprocess
key = "org.gnome.desktop.peripherals.touchpad" ;val = "send-events"
curr = subprocess.check_output(["gsettings", "get", key, val]).decode("utf-8").strip()
newval = "disabled" if curr == "'enabled'" else "enabled"
subprocess.Popen(["gsettings", "set", key, val, newval])
To use it
- Copy the script above, for your correct Ubuntu version, into an empty file, save it as
toggle_touchpad.py
-
Add the following command to a shortcut:
python3 /path/to/toggle_touchpad.py
Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
python3 /path/to/toggle_touchpad.py
Explanation
The command to disable touchpad:
for 14.04:
gsettings set org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled false
for 15.04 +:
gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
Read the current state
If we use a script to read the current settings by the command:
gsettings get org.gnome.settings-daemon.peripherals.touchpad touchpad-enabled
(14.04), or
gsettings get org.gnome.desktop.peripherals.touchpad send-events
(15.04+)
We can make the script set the opposite value, and thus toggle the touchpad.
EDIT; bash version of the toggle script
Just to be complete, and because OP indicated the python
script(s) worked, but not wanted to use python
, the bash
version(s) of the two toggle scripts:
14.04
#!/bin/bash
key="org.gnome.settings-daemon.peripherals.touchpad"
val="touchpad-enabled" ;curr="$key $val"
if [ "$(gsettings get $curr)" == "false" ]
then
gsettings set $key $val true
else
gsettings set $key $val false
fi
15.04+
#!/bin/bash
key="org.gnome.desktop.peripherals.touchpad"
val="send-events" ;curr="$key $val"
if [ "$(gsettings get $curr)" == "'enabled'" ]
then
gsettings set $key $val disabled
else
gsettings set $key $val enabled
fi
To put under a shortcut key
- Save the script as
toggle_touchpad.sh
-
put the following command under a custom shortcut:
/bin/bash /path/to/toggle_touchpad.sh