I have a new dell laptop and I want to create a keyboard shortcut to disable and enable the touchpad. How do I do this?
-
As promised after midnight, I wrote a comprehensive answer this morning. Sorry I didn't have the energy to do it last night but I think you'll like the end results :) – WinEunuuchs2Unix Dec 23 '16 at 17:43
3 Answers
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:

- 102,282
-
What command lines would you suggest for the scripts in order to work in standard Ubuntu? – sudodus Dec 23 '16 at 06:24
-
The command lines are provided in the link in the first sentence. – WinEunuuchs2Unix Dec 23 '16 at 06:25
-
Thank you. This method with 'xinput enable xx' and 'xinput disable xx' seems portable - should work will all Ubuntu flavours. – sudodus Dec 23 '16 at 06:44
-
Is there a way I can create one bash script with a conditional that, when run, would toggle the touchpad being on or off? I am just learning about scritpting now so any advice would be helpful! – MindlessMutagen Dec 23 '16 at 06:51
-
@sudodus Yes... I used it a couple months ago just to test on my system and it worked fine. It should be portable not just with touchpads but with mice too, etc. – WinEunuuchs2Unix Dec 23 '16 at 07:23
-
@MindlessMutagen yes you could create a script that toggles it and assign it to
Super
+T
shortcut... Just can't think of how right now as it's after midnight. Additionally you would have a notification pop-up "Touchpad On" or "Touchpad Off" because you only have one shortcut key combination you need the feed back. – WinEunuuchs2Unix Dec 23 '16 at 07:24 -
-
@MindlessMutagen blush... not not a wizard, although that would be cool. It's just a matter of having all these wonderful experts here in AskUbuntu post their great answers and learning from them... taking bits and pieces from hundreds of post and connecting the dots :) – WinEunuuchs2Unix Dec 23 '16 at 23:58
-
@sudodus As promised I've put together the script you were looking for last night. Sorry if I was rather cold about your own answer posted here last night... I was a little tired at the time. Hope you enjoy the final result above though :) – WinEunuuchs2Unix Dec 23 '16 at 23:59
-
@ WinEunuuchs2Unix, Thanks for a nice toggle script:-) I'm sure it works well with Dell laptops, and the question is about Dell. Unfortunately it does not work in my family's laptops, not in my Toshiba, not in our Lenovo X131e and not in the HP Elitebook, They use Synaptics TouchPad, and 'xinput list' prints the same string for enabled and disabled devices, so 'xinput list 14 | grep -Ec "disabled"' will never 'see a line'. But the basic switch, 'xinput enable 14' and 'xinput disable 14', works in these computers too (with the correct device number). – sudodus Dec 24 '16 at 03:30
-
You can replace
xinput list
with a different command that states when devices are enabled or disabled. Simpler method is two scripts one that turns the device on and one that turns it off. Thanks for taking the time to test it on your machines and your feedback :) – WinEunuuchs2Unix Dec 24 '16 at 03:35
Some computers have a function key for this purpose. For example, my Toshiba has FnF5.
You can do it rather easily via Settings -- Mouse & touchpad in standard Ubuntu. (the icon with the cog wheel and wrench).
Otherwise you can do it with terminal commands in the lightweight Ubuntu flavours
Disable:
synclient touchpadoff=1
Enable:
synclient touchpadoff=0
And you can make aliases for these commands, or a 'touchpad-toggle alias'.
See
man synaptics
for more details.
Option "TouchpadOff" "integer"
Switch off the touchpad. Valid values are:
0 Touchpad is enabled
1 Touchpad is switched off (physical clicks still work)
2 Only tapping and scrolling is switched off
When the touchpad is switched off, button events caused by a
physical button press are still interpreted. On a ClickPad,
this includes software-emulated middle and right buttons as
defined by the SoftButtonAreas setting.

- 46,324
- 5
- 88
- 152
-
This did not work on my Dell Inspiron 17R 7720 SE laptop. Touchpad driver is called
AlpsPS/2 ALPS GlidePoint
– WinEunuuchs2Unix Dec 23 '16 at 06:09 -
Which method and which flavour of Ubuntu? (I added alternatives, because I realized that there are different options in different cases.) – sudodus Dec 23 '16 at 06:12
-
Ubuntu 16.04 LTS 64-bit, Unity (regular) interface, current kernel. – WinEunuuchs2Unix Dec 23 '16 at 06:16
-
No, the synclient commands do not work in standard Ubuntu. They are probably overwritten or disabled by the tool behind 'Settings -- Mouse & touchpad', and the built-in function key works only in some computers. – sudodus Dec 23 '16 at 06:21
-
-
-
I could not make it the way I expected with via xinput because the state of the touchpad does not change, and I found no other variable that changes in the synaptics state. (I have a toggle, that I use in Lubuntu, but it does not work in standard Ubuntu.) – sudodus Dec 23 '16 at 08:38
Sources here, here, also here.
This script also shows a notification with icon, as well as message.
#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.
TOGGLE=$HOME/.toggle_touchpad
if [ ! -e $TOGGLE ]; then
touch $TOGGLE
xinput disable 14
notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png "Trackpad disabled"
else
rm $TOGGLE
xinput enable 14
notify-send -u low -i mouse --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png "Trackpad enabled"
fi
(in the above commands 14
is a variable to be identified with xinput list
)

- 3,444
- 2
- 34
- 85