Linux add shortcut keys to turn the touchpad on or off

Source: Internet
Author: User
Tags gtk

Linux add shortcut keys to turn the touchpad on or off

There are two commands that are used to turn the touchpad on and off

Command: Synclient touchpadoff=1--Close Touchpad

Command: Synclient touchpadoff=0--turn on touch pad

Www.ahlinux.com

The above command is unsuccessful, please look down.

However, you need to open the option Shmconfig first, or you can run these two commands with an error:

Can ' t access shared memery area. Shmconfig disabled?

To open this option, you need to add a file:

Gksudo GEDIT/ETC/HAL/FDI/POLICY/SHMCONFIG.FDI

The following content is placed in the file:

<?xml version= "1.0" encoding= "UTF-8"?>

<deviceinfo version= "0.2" >

<device>

<match key= "Input.x11_driver" string= "Synaptics" >

<merge key= "Input.x11_options. Shmconfig "type=" string ">on</merge>

</match>

</device>

</deviceinfo>

Each of the two shortcut keys can be tied to the two commands, such as <super>+f8 is open, <super>+f9 is closed, but this is inconvenient, it is best to a shortcut key can be switched between the two states. We need a script to do this thing.

Write a script file lockpad.py, which reads as follows:

#!/usr/bin/python

#-*-Coding:utf8-*-

#这段脚本用来关闭或打开触摸板, the runtime switches between the two states.

#使这段脚本起作用, you need to set the system's option Shmconfig to Yes first.

#Vivian Wang

Import subprocess

Stdreturn = subprocess. Popen (args= ' synclient-l ', shell=true, \

Stdout=subprocess. Pipe,stderr=subprocess. PIPE). Communicate ()

If Len (Stdreturn) ==0:www.ahlinux.com

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 should 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)

The script will read first whether the current state of the touchpad is on or off, and then call the corresponding command to turn it on or off.

Use

chmod +x lockpad.py

Set it to executable.

Binding shortcut keys you need to tick commands in Compizconfig and then add a command:

/home/vivian/lockpad.py www.ahlinux.com

Point to the script file in the preceding section.

Then, in the key Bindings page, set the binding key value for this command to <SUPER>+F9.

This toggles between turning the touchpad on and off when <SUPER>+F9 is pressed.

After practice, commands are always valid. But there are also accidents, there will be shmconfig open state failure situation, the system or error said "Shmconfig should be enabled.", the specific reason is not clear, it seems that the use of compizconfig is prone to this situation. The above script, in this case, pops up a dialog box to prompt you. If this happens, it's OK to reboot the system normally.

To make the above script run up, you need to install Python2. X, python-gtk2 these components.

Author Tycomputer

    • This article from: Hobby Linux Technology Network

Linux add shortcut keys to turn the touchpad on or off

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: info-contact@alibabacloud.com 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.