I am using ubuntu 14.04. I have currently disabled the trackpad of my laptop by turning it off in "System settings -> Mouse & Touchpad". Can I set a keyboard shortcut to toggle the trackpad on and off like the option in the system settings?
Keyboard Shortcut – How to Toggle Trackpad On/Off
shortcut-keyssystem-settingstrackpad
Related Solutions
Script to toggle Touchpad on/off with screen notification
Partial credit to this post (Enable/disable touchpad)
Create toggle-touchpad script
Create a new directory /home/USER/bin
and then use gedit /home/USER/bin/toggle-touchpad
. NOTE: Replace USER with your user ID. Copy and paste these lines into your editor:
#!/bin/bash
# NAME: toggle-touchpad
# PATH: /home/$USER/bin
# DESC: Update pulseaudio output device when HDMI TV plugged / unplugged
# CALL: called from Keyboard Shortcut `Super`+`T`
# DATE: Created Dec 23, 2016.
# NOTE: Written for AU question: http://askubuntu.com/questions/863746/keyboard-shortcut-to-disable-the-laptop-touchpad/863750?noredirect=1#comment1333958_863750
# Use device number matching touchpad, in this case 14
if [[ $(xinput list 14 | grep -Ec "disabled") -eq 1 ]]; then
xinput enable 14
DISPLAY=:0 notify-send --urgency=critical --icon=/usr/share/icons/gnome/256x256/status/user-available.png "Touchpad enabled"
else
xinput disable 14
DISPLAY=:0 notify-send --urgency=critical --icon=/usr/share/icons/gnome/256x256/status/user-busy.png "Touchpad disabled"
fi
exit 0
Mark toggle-touchpad script as executable
Save the file and exit the editor. Now flag the file as executable using chmod +x /home/USER/bin/toggle-touchpad
Assign toggle-touchpad script to keyboard shortcut
Open up System Settings
⟶ Keyboard
⟶ Shortcuts
⟶ Custom Shortcuts
⟶ +
This screen appears:
Fill in the Custom Shortcut fields like this:
- Name =
Toggle Touchpad
- Command =
/home/USER/bin/toggle-touchpad
Click Apply button to save.
The new entry appears with status Disabled. Right click on Disabled and use Super+Z (or any other unused shortcut combination). I wanted to use Super+T but that is already assigned to Nautilus Trashcan.
Modify toggle-touchpad script to different device number
The default device number is set at 14. To find out what your device number is use the following:
───────────────────────────────────────────────────────────────────────────────
USER@host:~/bin$ xinput
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech Performance MX id=10 [slave pointer (2)]
⎜ ↳ Logitech K800 id=11 [slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS GlidePoint 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)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ Sleep Button id=9 [slave keyboard (3)]
↳ Laptop_Integrated_Webcam_HD id=12 [slave keyboard (3)]
↳ Dell WMI hotkeys id=15 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]
───────────────────────────────────────────────────────────────────────────────
USER@host:~/bin$
You can pick any device you like, ie Touchpad = 14, Webcam = 12, etc.
Which ever device number you use, simply open your /home/USER/bin/toggle-touchpad
script and replace 14
with that device number.
Modify toggle-touchpad script to use different icons
When the "Touchpad enabled" / "Touchpad disabled" notification bubble is displayed, an icon is displayed left of the text. Stock icons are used from /usr/share/icons/gnome/256x256/status/
but you can change them.
For enabling touchpad this is displayed:
For disabling touchpad this is displayed:
First step would be to create scripts to connect and disconnect WiFi hotspot. See this Q&A for options: How to connect to WiFi from the command line?
To see list of available WiFi hotspots ()
nmcli d wifi list
Sample Script to connect:
#!/bin/bash
nmcli d connect <WifiInterface>
Sample Script to disconnect:
#!/bin/bash
nmcli d disconnect <WifiInterface>
Marks the scripts as executable with chmod
:
sudo chmod a+x /path/to/script-name
Assign shortcut keys to scripts: How do I setup keyboard macros?
NOTE: Have your password automatically saved with your WiFi profile so it doesn't have to be reentered every time it is started up.
Best Answer
You can place a small script that checks the current state under a shortcut key, and make it subsequently switch to the other state.
This works in a lot of situations, eg toggling the trackpad, toggling visibility of (many) indicator icons etc. (see EDIT, down in the post)
The script below does that:
How to use
toggle_touchpad.py
Test-run it by running (in a terminal) the command:
If all works fine, add it to a shortcut key combination: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
Now the shortcut key should toggle the touchpad on/off
Explanation
The touchpad is enabled / disabled by the key:
To get the current state:
To set to
enabled
To set to
disabled
:Notes
1. Using absolute paths in Custom keyboard shortcuts
Like in
.desktop
files, relative paths like~
cannot be used in custom keyboard shortcuts. Also, just like in terminal commands, spaces need to be escaped:Instead of:
use:
2. Using the command(s) in 15.04
Due to a bug (it seems) the command:
works fine, however the command:
needs to run twice (!!) to disable the touchpad...
3. Bash version of the script
For those who prefer a
bash
version for some reason:Save it as
toggle_touchpad.sh
, run it with the commandEDIT
The script(s) above can be used to toggle any setting, done by a
gsettings
command, of the typeboolean
(false/true). Simply change the line:By the corresponding key.
An example:
If I change the line to:
It toggles visibility of the sound indicator icon.