| Member with 69 posts. THREAD STARTER | | Join Date: Aug 2008 Location: St. Thomas, Ontario, Canada Experience: electronics engrg technol | |
Kubuntu: F-Key Your TouchPad Off/ON-A Different Approach KUBUNTU: HOW TO TURN THE TOUCHPAD OFF AND ON WITH ONE Shortcut KEY I did a post earlier on at http://ubuntuforums.org/showthread.php?t=914537&page=2 where I submitted what I had discovered about turning the touchpad off and on. Quote:
sudo rmmod psmouse -----> Turns the touchpad OFF
sudo modprobe psmouse ---> Turns the touchpad ON
|
But I still desired to do this with a shortcut key instead of terminal input. Then I found a method of doing this at: https://help.ubuntu.com/community/Sy...ad/ShortcutKey but nothing worked in my Kubuntu environment for whatever reason. Neither synclient nor syndaemon worked, nor did gsynaptic, ksynaptic, or qsynaptic. Furthermore even bindkeys and bindkeys-config refused to function at all.
Therefore, facing all these 'downers' I set out to find another method using the code that did work in my system, on my MDG VisionBook laptop. It has a FnF3 key that is supposed to turn the touchpad off and on (according to the manual) but it never did work! I have often wondered if it was ever meant to work and is just there as a decoration gadget? Anyway, knowing that rmmod psmouse and modprobe psmouse worked to turn the touchpad off and on, I worked out the following method for setting up a shortcut key to turn the touchpad off or on with a single key press.
So here it is. It works for me and I hope it works for you also if you need it.
---------------------------------------------------------------------------- STEP 1 Using a text editor create a flag file called tpon in the /usr/local/bin folder. It does not matter if the file is empty or has a comment line in it as mine does (shown below)-the file acts as a flag to tell the touchpad.py program script (below) the current state of the touchpad.
*** Create Flag File tpon *** Code: # touchpad flag file
=========================================================================== ========================== STEP 2 Contents of Executalble File: touchpad.py (make executable with chmod 755 touchpad.py) You can simply cut and paste the code below, starting with '#!/bin/bash' down to 'exit 0'. Code: #!/bin/bash
file1="/usr/local/bin/tpon" # tpon is the flag file when the touchpad isactive
file2="/usr/local/bin/tpoff" # tpoff - the flag file with deactivated toucpad
if [ ! -e "$file2" ] # check for NON-existence of 'tpoff' flag file
then # if tpoff is NOT found then touchpad is ON
rmmod psmouse # so turn the touchpad OFF
mv $file1 $file2 # rename the flag file to 'tpoff' to reflect state
else # tpoff flag file EXISTS so touchpad is OFF
modprobe psmouse # so turn the touchpad ON
mv $file2 $file1 # rename the flag file to 'tpon' to reflect state
fi # end of conditional code for touchpad state
exit 0 # Leave the program with a zero return code.
STEP 3 Make the above file (touchpad.py) executable by entering, in a terminal as root, the code: chmod 755 touchpad.py
-------------------------------------------------------------------------------- STEP 4 Set up the Key or Key combination of your choice to run the touchpad.py script file. I have chosen the F3 key so the following text will specify F3 but you can set it to whatever you prefer.
The F3 key or any key you choose activates the touchpad.py file shown above.
The first time the F3 key is pressed, the touchpad turns off and the next time it is pressed the touchpad is turned on. This continues in an alternating pattern.
When you log onto the system the next time, the TouchPad will be activated during system logon but after you log on pressing the F3 key will alternately deactivate and activate the TouchPad.
----------------------------------------------------------------------------------- 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: 7) Go down the 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.py". 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 3 more things to make this all work.
------------------------------------------------------------------------------- STEP 5 Edit your sudoers file to allow you to execute the script without a password. 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.py
NOTE: Make sure to replace {user} with your own login user name ---------------------------------------------------------------------------------------------------------------- STEP 6 Everytime you restart the computer the touchpad will be active (ON). Because you may have exited Linux with the touchpad OFF, the tpoff flag file will have been left in the /usr/local/bin folder. Thus the first press of the shortcut key would would turn send the command to turn the touchpad ON (when the touchpad is already on) and the tpoff file would be renamed to tpon. The second press of the shortcut key would then turn off the touchpad since the correct flag file (tpon) would now be in existence. IF YOU DO NOT MIND THE EXTRA KEY PRESS then you are now DONE! - otherwise - continue...
The solution to this extra key press at startup is to begin each bootup with a known state of the touchpad. That is to say that the touchpad will be ON after a bootup, but the flag file may be tpoff instead of tpon. In the above explanation I pointed out that pressing the shortcut key the first time will cause the code to turn the touchpad ON (modprobe psmouse) to be executed and thus the touchpad will still be on, but the flag file will now have been changed from tpoff to tpon so that the flag file is in agreement with the state of the touchpad. From that point on each key press will change the state from off to on in an alternating fashion. This result can be achieved automatically by having a small script execute automatically at startup.
To do this you require the KDE Control Centre to be installed if it is not already installed.
You can install the package from a terminal with ------------------------------------------------------------------------------------------------------------------------- [a]- Write a script called .... set-tpon.sh The script set-tpon.sh will be started automatically.
This script will ensure that the flag file is named tpon at every session startup.
If the file left in the /usr/local/bin folder is tpoff then it will be changed to tpon .
If it is already named tpon then nothing will be done.
Put the following script (named set-tpon.sh) into the /usr/local/bin folder. Code: #!/bash/bin
file1="/usr/local/bin/tpon"
file2="/usr/local/bin/tpoff"
if [ -e "$file2" ]
then
mv $file2 $file1
fi
exit 0 After saving the above script file make it executable with the code: chmod 755 set-tpon.sh
-now continue with step [b] below:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [b] - To set up the autostart of the script file, do the following: 1) Start up KDE Control Centre. 2) Select KDE Components from the menu list. 3) Click on Autostart Manager. 4) On the window that appears next click the [Add] button. 5) On the screen that pops up enter in the window the following code: Code: /usr/local/bin/set-tpon.sh 6) Check (click) on the box next to "Run in terminal" 7) On the next window that appears click on the Permissions tab. Check (click) the box next to "Is executable". 8) Click on OK. 9) Click on Apply and exit KDEControlCenter.
=========================================================================== == STEP 7 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 could do on the fly at this time with what I know). walt 2008.09.19 
Last edited by wladicus; 20-Sep-2008 at 01:02 PM..
Reason: Formatting corrections
|