|
Style Cleanup Required |
|
Content Cleanup Required |
Turning Synaptics Touchpads On/Off with a Shortcut Key
You may wish to turn the touchpad on or off so that it doesn't interfere with typing when using a USB or other mouse.
Use following steps:
Step 1
Ubuntu version <= 8.04 (Hardy Heron)
from a terminal, edit /etc/xorg.conf
gksudo gedit /etc/X11/xorg.conf
and look for the following section of code:
Section "InputDevice" Identifier "Synaptics Touchpad" Driver "synaptics" Option "SendCoreEvents" "true" Option "Device" "/dev/psaux" Option "Protocol" "auto-dev" Option "HorizScrollDelta" "0" EndSection
and add one more Option at the End of the Section:
Option "SHMConfig" "on" EndSection
If you are using an Alps-Touchpad, which you can find out by typing
cat /proc/bus/input/devices
your code section should look like this
Section "InputDevice" Driver "synaptics" Identifier "TouchPad" Option "SendCoreEvents" "true" Option "Device" "/dev/input/event2" Option "Protocol" "event" Option "SHMConfig" "on" EndSection
You can define some parameters which influence the behaviour of your touchpad. These parameters are presented already in https://wiki.ubuntu.com/SynapticsTouchpadWartyHowto?highlight=%28touchpad%29. You can check if your touchpad works correct and you have the correct parameters with
synclient -m l
If everything works fine, the position of your finger will be updated everytime you move it and based on this information you can set your parameters.
Ubuntu 8.10 (Intrepid Ibex)
Ubuntu 8.10 (Intrepid Ibex) uses HAL, and so synaptic settings are placed in an fdi file instead of xorg.conf. To enable SHMConfig see here: https://help.ubuntu.com/community/SynapticsTouchpad#shmconfig
Step 2
In this next part we will create a script to toggle the touchpad. There are a couple of ways to write the scripts to toggle the touchpad on and off. The first method uses Python, the second method uses a more simple bash script. Choose the one you like the most.
Step 2a
Next we will create 3 files - a bash script to turn the touchpad off, one to turn it on, and a python script to use a single key combination for both. At a terminal, cd to /usr/local/bin and make a new file:
cd /usr/local/bin gksudo gedit tpoff
and paste the following code in the file, save it and close it.
# synclient touchpadoff=1
again, make a new file:
gksudo gedit tpon
paste the following, save and close:
# synclient touchpadoff=0
once again, make a new file:
gksudo gedit touchpad.py
paste the following, save and close
import os def ReadFile(): myfile = open('/tmp/synclient.tmp', 'rb') for line in myfile: TestString(line) myfile.close() def TestString(string): for word in string.split(): if word == "TouchpadOff": setting = string.split() ChangeState(setting[2]) def ChangeState(current): if current == "0": os.system("synclient touchpadoff=1") else: os.system("synclient touchpadoff=0") os.system("rm /tmp/synclient.tmp") def Main(): ReadFile() os.system("synclient -l > /tmp/synclient.tmp") Main()
and finally, change the permissions of these three files:
sudo chmod 755 tpon tpoff touchpad.py
Step 2b
First open a terminal and cd to /usr/local/bin and make a new file:
cd /usr/local/bin gksudo gedit toggletouchpad
and paste the following code in the file, save it and close it.
state=`synclient -l | fgrep TouchpadOff | sed 's/^.*= //'` if [ $state -eq 1 ] then synclient TouchpadOff=0 else synclient TouchpadOff=1 fi
Next, change the permissions of this file:
sudo chmod 755 toggletouchpad
Step 3
Next, edit your sudoers files to allow you to execute the script without a password.
sudo visudo
and add this line
{user} ALL = NOPASSWD: /usr/local/bin/{script name}
where {user} is your user name and {script name} is the name of the script you created.
save (in nano hit <CTRL> <o>), and make sure to save it as: /etc/sudoers and not /etc/sudoers.tmp
Step 4
Alternatively to setup bellow, you might use gnome-keybindings(In depth instructions, 4.) or other desktop-dependent tool.
Next, install xbindkeys
sudo apt-get install xbindkeys
when it's done, install xbindkeys-config, the GUI for xbindkeys
sudo apt-get install xbindkeys-config
once each is installed, start both applications:
xbindkeys
and
xbindkeys-config
edit your file to the shortcut key you want. For example, to be able to switch the touchpad on/off by <Ctrl><F5>, fill in the following, under Edit:
Name: Touchpad On/Off Key: Control + F5 | m:0x4 + c:71 Action: /usr/local/bin/touchpad.py
then click apply & save & exit (change the script name in the 'Action' field if you used the other method.)
Now that that is done, restart xbindkeys:
xbindkeys
You may need to restart X.
Remember that each time you restart X, you will need to run xbindkeys again in order for the shortcut to work. Go to System>Preferences>Sessions>Startup Programs> click add type xbindkeys then click ok.
Bash Script
Instead of using the 3 scripts above, you can achieve the same thing with a single bash script:
# toggle synaptic touchpad on/off # get current state SYNSTATE=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') # change to other state if [ $SYNSTATE = 0 ]; then synclient touchpadoff=1 elif [ $SYNSTATE = 1 ]; then synclient touchpadoff=0 else echo "Couldn't get touchpad status from synclient" exit 1 fi exit 0
Using xinput
The following script does not need SHMConfig to be enabled - it works on out-of-the-box Ubuntu. It does not need any of the steps above to be performed. Works without superuser rights.
Besides that, it does exactly the same as the one above.
export `xinput list | grep -i touchpad | awk '{ print $6 }'` TOUCH_ENABLED=`xinput list-props $id | grep Device\ Enabled | awk '{ print $4 }'` if [ $TOUCH_ENABLED = 0 ]; then xinput set-prop $id "Device Enabled" 1 elif [ $TOUCH_ENABLED = 1 ]; then xinput set-prop $id "Device Enabled" 0 else echo "Could not get touchpad status from xinput" exit 1 fi exit 0
The following sh/bash shell script is a refinement of the script above. It eliminates use of the 'export' command in favor of a simple variable assignment and includes some comments and prints a message confirming the action taken.
# # tp_toggle # # Toggle the touchpad on/off. # Get the id number of the touchpad. tp_id=`xinput list | grep -i touchpad | awk '{ print $6 }' | sed 's/id=//'` # Find out whether the touchpad is enabled or not. tp_enabled=`xinput list-props $tp_id | grep Device\ Enabled | awk '{ print $4 }'` if [ $tp_enabled = 0 ] then # The touchpad is currently disabled, so turn it on. xinput set-prop $tp_id "Device Enabled" 1 echo "Touchpad now on." elif [ $tp_enabled = 1 ] then # The touchpad is currently enabled, so turn it off. xinput set-prop $tp_id "Device Enabled" 0 echo "Touchpad now off." else echo "tp_toggle: Could not get touchpad status from xinput." exit 1 fi
Open a terminal and type:
gedit touch_toggle.sh
Copy and paste the script into the open text doccument, then save your document and close the text editor.
In your open terminal enter:
chmod +x touch_toggle.sh
to make your script executable.
Expose your launcher and click the; System Settings icon, in the pop up window select; Keyboard, and then the; Shortcuts tab. From this tab select; Custom Shortcuts, and then the "+" icon. In the pop up enter a name for your shortcut (touch_toggle works nicely), and then in the command box enter:
./touch_toggle.sh
Then click; apply, and you should now have a new entry listed as disabled. Click on the "disabled" in your new entry, then press the keys you wish to toggle your touchpad with, this should set your desired key combination to run the touchpad toggle script.
Using xinput on Ubuntu 15.10
The above example using awk to print $6 doesn't seem to work on Ubuntu 15.10 which wants a long device name like "AlpsPS/2 ALPS DualPoint TouchPad". This /bin/bash script toggles it:
declare -a STATES=(1 0) DEVICE=$(xinput list --name-only | grep TouchPad) STATE=$(xinput list-props "$DEVICE" | grep 'Device Enabled' | sed 's/^.*:[ \t]*//') xinput set-prop "$DEVICE" 'Device Enabled' ${STATES[$STATE]}