How to enable/disable the touchpad/trackpad in Ubuntu 22.04 from the command-line, including automatically if an external mouse is plugged in
For anyone just looking for this, here's how.
Tested on Ubuntu 22.04 with the default Wayland display server as well as the X11 display server (I recommend X11--see why at the end of my answer here).
If using the new (and default, as of Ubuntu 22.04) Wayland display server rather than the X display server,
xinput won't work to try to disable the touchpad or touchscreen. Instead, use
gsettings. On Ubuntu 22.04 at least (I haven't tried it on earier vresions of Ubuntu), even with the X11 display server,
gsettings works as well. Here is how:
# disable the touchpad
gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
# enable the touchpad
gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
# enable the touchpad automatically if an external mouse is NOT plugged in, but
# disable it automatically if one is
gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled-on-external-mouse
# get the current setting
gsettings get org.gnome.desktop.peripherals.touchpad send-events
To see what settings are available, run the
gsettings range command. Here is the command and its output, showing all 3 settings options I presented above:
$ gsettings range org.gnome.desktop.peripherals.touchpad send-events
The way I figured this stuff out is by digging around in the
dconf-editor settings to explore what settings and options existed.
Install it with:
sudo apt update
sudo apt install dconf-editor
Here is a screenshot of the
org.gnome.desktop.peripherals.touchpad settings page in it:
Note also that you can open your regular Ubuntu "Settings" --> "Mouse & Touchpad" --> and view the "Touchpad" enable toggle turn on and off as you manually run the enable/disable command-line commands above:
To figure out how to disable other external devices, such as touchscreens, trackballs, tracksticks, etc, go up a couple levels to the
org.gnome.desktop.peripherals section of the
dconf-editor, and drill down to explore their settings from there:
- My touchpad_toggle.sh script which uses the code above and is part of my eRCaGuy_dotfiles repo. It allows you to rapidly enable/disable your touchpad and/or touchscreen, as well as fix your mouse wheel scroll speed simultaneously. I've used it on Ubuntu 14.04, 16.04, 18.04, 20.04, and 22.04, using both the Wayland and X11 window servers on Ubuntu 22.04. See also my answer here: How to permanently fix scroll speed in Chrome, Sublime Text, Foxit PDF reader, and any other application you see fit.
- My answer which links to this one: Enable/disable touchpad