Add shortcut keys to enable or disable the touchpad in Ubuntu

Source: Internet
Author: User
Tags gtk

Two commands are used to enable or disable the touchpad.
Command: synclient touchpadoff = 1 -- close the touchpad
Command: synclient touchpadoff = 0 -- enable the touchpad
But you need to open the option shmconfig first. Otherwise, an error will be reported when you run these two commands:
Can't access Shared memery area. shmconfig disabled?

To enable this option, you need to add a file:
Gksudo gedit/etc/hal/fdi/policy/shmconfig. FDI
Put the following content in the file:
<? XML version = "1.0" encoding = "UTF-8"?>
<Deviceinfo version = "0.2">
<Match key = "input. x11_driver" string = "synaptics">
<Merge key = "input. x11_options.shmconfig" type = "string"> On </merge>

You can bind two shortcut keys to the two commands respectively. For example, <super> + F8 is enabled, and <super> + F9 is disabled, but this is inconvenient, it is better to have a shortcut key to switch between the two States. We need a script to do this.

Write a script file lockpad. py with the following content:

#! /Usr/bin/Python
#-*-Coding: utf8 -*-
# This script is used to close or open the touchpad, And will switch between the two States during running.
# To make this script take effect, you must first set the System Option shmconfig to yes.
# Vivian Wang
Import subprocess
Stdreturn = subprocess. popen (ARGs = 'synclient-l', shell = true ,\
Stdout = subprocess. Pipe, stderr = subprocess. Pipe). Communicate ()
If Len (stdreturn) = 0:
Exit ()
Vl = stdreturn [0]. Split ()
I = Vl. Index ('touchpadoff ')
If I <0:
Import GTK
Import pygtk
MD = GTK. messagedialog (none ,\
GTK. dialog_destroy_with_parent, GTK. message_info ,\
GTK. buttons_ OK, "shmconfig shocould be enabled .")
Md. set_position (GTK. win_pos_center)
Md. Run ()
Md. Destroy ()
Exit ()
Subprocess. popen (ARGs = 'synclient touchpadoff = '+ STR (1-int (VL [I + 2]), shell = true)

This script first reads whether the current status of the touchpad is enabled or disabled, and then calls the corresponding commands to open or close it.
Chmod + x lockpad. py
Set it to executable.

To bind a shortcut key, select commands in compizconfig and add a command:
/Home/Vivian/lockpad. py
Point to the script file above.
Then, on the key bindings page, set the BIND key value corresponding to this command to <super> + F9.
In this way, when you press <super> + F9, the system switches between enabling and disabling the touchpad.

After practice, the command is always valid. However, there may also be unexpected situations where the shmconfig enabling status becomes invalid. The system still reports an error saying "shmconfig shoshould be enabled. ", the specific reason is unclear. It seems that compizconfig is prone to this situation. In this case, a dialog box is displayed. If this happens, restart the system and you will be OK.

To make the above script run, you need to install python2.x, python-gtk2 these components.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.