2012-03-23 Toggle Touchpad

Not all laptops have a functioning button for toggle the touchpad on and off out of the box with Linux. I've made a script that does this by removing the mouse module from the Linux kernel and then putting it back again to enable the pointer again. This means that the script can be used also on desktop computers to temporarily disable the mouse.

These instructions have been designed and tested for Ubuntu Oneiric (11.10) but should work for other flavours of Linux possibly with minor changes.

These instructions are provided with absolutely no warranty.

  1. Put the following in a file, e g "/usr/local/bin/toggle-touchpad" This script will check if the module is loaded, remove it in case it is, or put it back if it is not loaded.

  2. Change owner to rootsudo chown root /usr/local/bin/toggle-touchpad
  3. Open a root shell, for example using sudo bash.

    Warning: the following part of the instructions is dangerous and may leave your installation crippled if done wrong or not not working for other reasons! If things fail you might have to use a live media to remove the file described below.

  4. Create a file "/etc/sudoers.d/sudo-toggle-touchpad" with these contents: %users ALL = NOPASSWD: /usr/local/bin/toggle-touchpad The file must end with a newline. If your user is not in the users group, replace %users with your user name (without the percentage sign).
  5. Change the file mode like this: chmod 440 /etc/sudoers.d/sudo-toggle-touchpad
  6. Open another shell and test that you can run sudo without problems. If not, remove the file /etc/sudoers.d/sudo-toggle-touchpad .

    Warning: exit the root shell only when you know that sudo works.

  7. Done! Now you can enable and disable the touchpad or mouse using the command sudo toggle-touchpad.
  8. Now you can use any means you like to activate this script to toggle the touchpad or mouse, e g Gnomes or KDEs key bindings, or something else.