How-to: Create a keyboard shortcut to toggle touchpad on Ubuntu
Mar 11, 2017 · 2 minute read · Commentstipsubuntu
I recently got myself a new laptop, a thin and light one. The best thing about it is amazing portability, so I don’t want to hinder it by carrying tons of accessories such as mouse all the time. That means relying on built-in touchpad. And what is the most annoying thing about touchpad? It’s so easy to touch it involuntarily while typing and move the cursor away. Yes, the software that controls the touchpad can disable it when the keyboard is used. Also, there are various sensitivity settings that can be tweaked. But still, it’s not perfect and you get the cursor moved and UI controls clicked by accident, if you’re not careful enough. So, it’s better to disable the touchpad completely when not needed.
The problem
My laptop doesn’t have a built-in button to disable the touchpad. But it turns out that it’s quite easy to create a keyboard shortcut to toggle the touchpad state.
The following solution was tested on Ubuntu 16.04 LTS.
The solution
Create the script touchpad_toggle.sh
with the following content:
#!/bin/bash
SCHEMA=org.gnome.desktop.peripherals.touchpad
KEY=send-events
STATUS=`gsettings get $SCHEMA $KEY`
if [ "$STATUS" == "'disabled'" ]
then
gsettings set $SCHEMA $KEY 'enabled'
else
gsettings set $SCHEMA $KEY 'disabled'
fi
Then, make the script executable by running:
chmod +x touchpad_toggle.sh
Next, open the keyboard configuration settings. Switch to the Shortcuts
tab and select Custom shortcuts
.
Then, add a new shortcut and set the Command
to the path to the script created in the previous step.
Select the newly created shortcut and press the keys combination that you want to use for disabling/enabling the touchpad.
That’s it. Your shortcut should be active.
Conclusion
I find it very useful to be able to disable the touchpad. I do it mainly for coding and writing. It does encourage you to learn and use more keyboard shortcuts, which is good as it should make you more efficient. However, not every application is designed to be used with keyboard only, so it is important to be able to switch the touchpad on and off quickly.