Kubuntu: How To Turn The Touchpad Off And On With One Shortcut Key
This guide explains how you can turn your touchpad on or off on a Kubuntu laptop by using a shortcut key.
Some of you with laptop computers may identify with the frustrations of runaway cursors and surreptitiously deleted text at the most inopportune moments. Any of this can happen when your thumb brushes over the touchpad while you are typing. It is truly an annoyance.
Now some of you are fortunate enough to have a working function key that switches the touchpad off and on at the ‘push of a button’. My laptop has such a key (Fn+F3) but it has never worked! Also some of you may have mouse/touchpad drivers that provide a choice to turn the touchpad off or on at the ‘check of box’ or ‘click of button’. This is usually the case if the laptop has a Synaptics touchpad installed, with the accompanying Synaptics driver. For others, the daemon routines in Linux may provide the answer (syndaemon, and synclient setting the option “SHMConfig” to “on” in etc/X11/xorg.conf). Other things I tried that did not work included synclient, syndaemon, gsynaptic, ksynaptic, qsynaptic, bindkeys and bindkeys-config.
I tried all of the proposed solutions, but nothing seemed to work on MY laptop running Kubuntu 8.04 LTS (Hardy Heron) with the KDE3 desktop. I do not know why. No one seemed to know why. Maybe the way the manufacturer designed this laptop from piecemeal components from various sources confuses the Linux code set in the device specific area of the touchpad (which is of Logitech manufacture).
Finally I found one person who sent me simple coding to turn off and on the device driver in Linux. His avatar pseudonym was Dootzky and it was at
this forum location.
The code in essence removes the touchpad driver and is as follows:
Code:
sudo rmmod psmouse # Turns the touchpad OFF
sudo modprobe psmouse # Turns the touchpad ON
This was great but strictly manual from a terminal. I had in mind that this could be done from a shortcut key. I must mention here that I am a complete newbie in Linux and was at it for barely a month when I decided to tackle some coding using flag files to track the state of the touchpad etc. It worked well for me so I posted it on a couple of sites.
This resulted in significantly good feedback and lead to the following improved method.
Step 1 ---------------------------------------------------------------------------------------------------------
Using a text editor create a script file name
touchpad.switch (if you prefer another name then change it, but remember to change it in all the appropriate places later on in this article) from either
Code 1: or
Code 2:
Place the touchpad.switch file into /usr/loca/bin folder.
Code 1 (suggested by a Linux enthusiast ‘zCat’ deactivates the touchpad in essence by removing the driver from active service and then reactivates it).
Code 2 (a bit longer) was suggested by a Linux enthusiast ‘Rudo’ who deplores removing drivers to achieve a result and therefore came up with his version which only takes ˝ second longer to run.
You can choose
Code 1 or
Code 2, whichever delights you most (I do not know the advantage of either, but I decided to take “Rudo’s” approach for myself. I tested both methods and both work well. (you can copy and paste the code you choose –
Code 1 or
Code 2).
File Name:
touchpad.switch Code 1:
Code:
#!/bin/bash
lsmod | grep -q psmouse && rmmod psmouse || modprobe psmousefile2
exit 0
Code 2:
Code:
#!/bin/bash
SERIO_PATH=/sys/bus/serio/devices/serio2
if grep -q auto $SERIO_PATH/bind_mode
then
# it is on, turn it off:
echo -n manual > $SERIO_PATH/bind_mode
echo -n none > $SERIO_PATH/drvctl
else
# turn it back on:
echo -n auto > $SERIO_PATH/bind_mode
echo -n reconnect > $SERIO_PATH/drvctl
fi
exit 0
Step 2 ---------------------------------------------------------------------------------------------------------
Make the above file (
touchpad.switch) executable by entering, in a terminal as root, the following:
Code:
chmod 755 touchpad.switch
Step 3 ---------------------------------------------------------------------------------------------------------
Set up the Key or Key combination of your choice to run the
touchpad.switch script file. I have chosen the F3 key so the following text will specify F3 but you can set it to whatever you prefer.
How To Set Up The Key To Turn The Touchpad Off Or On
---------------------------------------------------------------------------------------------------------
1) Bring up the Desktop Menu and right-click anywhere on the menu that has an arrow at the right side (indicating submenus).
[If you click on an item without further submenus then a small box with three choices will "pop up". The second choice will be to "Edit Item" but clicking on an item with submenus will have only two choices in the pop-up box and the second choice will be "Edit Menu". That is the one we need].
2) So now you have the pop-up box with only two choices. The second item displayed is "Edit Menu".
3) Left-click on this second item. The KDE Menu Editor will come up. If it is hidden behind the existing menu (as it always is in my case) then simply click your mouse pointer on the KDE Menu Editor and it will become the menu of focus.
4) In the existing list of menu items CLICK on or highlight the submenu where you wish the 'hide' this touchpad application. I chose the 'Utilities' submenu item. (Since we are going to activate this 'switch' application with a keyboard key, we do not really have to have it readily accessible in the menu.
But we have to put it somewhere in this menu to be able to use the 'key setting' ability that it provides for launching the application.
5) Now click the [File] menu item at the top and select [New Item]. In the small window that pops up enter the name you wish to call this application. I named it [TouchPad Off/On Switch]. After naming the application click on [OK]. This will place the name you just typed into the submenu you just selected (which, as I said, in my case, was in the 'Utilities' submenu).
6) Now hilite (click on) the application name that you just placed in your submenu of choice and you will see on the right-hand side of the KDE Menu Editor window "Name: -the name you chose is entered in the box-".Go Down 3 boxes to the one entitled "Command". Click on this box and enter the following:
Code:
sudo touchpad.switch
7) Go down to the item that says "Run in terminal" and place a checkmark (click) in the box in front of "Run in terminal". Every time you press the short-cut key you will see the terminal briefly flash in and out of view. This visibly indicates that the application is being launched by the terminal command "sudo touchpad.switch".
8) The last item at the bottom of the window is "Current shortcut key". This item will enable us to set a shortcut key to launch the touchpad switch application. In the box next to "Current shortcut key" it probably says [None]. Click on this box and in the ensuing pop-up screen next to the word "Shortcut:" you should see an empty box. Now press the key or key combination of your choice and you should see it appear inside this box. If your key choice has already been allocated then you will see a Conflict window pop up. If you still wish to use your chosen key combination then click on [Reassign]. Now the previous KDE Menu Editor window will be in focus with the box at the bottom right showing your key selection.
9) Click on the diskette 'save' icon or [File][Save] to save your key choice. Wait for the save action to complete (about 1 second) then exit the KDE Menu Editor.
The touchpad switch application is now prepared for launching with your chosen keyboard key or key combination. But first we must do 1 more thing to make this work without having to enter your password after each F-key press.
---------------------------------------------------------------------------------------------------------
Step 4
---------------------------------------------------------------------------------------------------------
Edit your sudoers file to allow you to execute the script without a password. The sudoers file is found in folder
/etc therefore,
cd /etc before entering one of the two editing methods shown below:
Quote:
Edit using ----> sudo visudo
... or use ----> sudo nano sudoers
|
Near the end of the sudoers file you will see a section of code similar to the following:
Code:
# User privilege specification
root ALL=(ALL) ALL
# Members of the admin group may gain root privileges
%Admin ALL=(ALL) ALL
Copy & paste the following code to the end of the above segment of code into the sudoers file:
Code:
{user} ALL=NOPASSWD: /usr/local/bin/touchpad.switch
NOTE: Make sure to replace
{user} with your own login user name
Step 5
---------------------------------------------------------------------------------------------------------
Reboot your system.
Now you can turn your touchpad off and on by pressing the key or key combination that you selected (in my case it is F3). If anyone finds improvements to the above, I would be happy to learn about them.(Please remember that I am a neophyte with only one month of experience with Linux and this is the best I have come up with up until this time with the help of a few weathered Linux enthusiasts.
walt
2008.10.04