xinput.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # a script to disable/enable mouse device
00004 import subprocess
00005 import re
00006 def getList():
00007     # array of array such as:
00008     # [['Virtual core pointer', 2], ['Power Button', 7], ...]
00009     name_output = subprocess.check_output(["xinput", "list", "--name-only"]).split("\n")
00010     id_output = subprocess.check_output(["xinput", "list", "--id-only"]).split("\n")
00011     return [[name, int(id)] 
00012             for name, id in zip(name_output, id_output)
00013             if name and id]
00014 
00015 def setDeviceEnable(id, enable):
00016     subprocess.check_call(["xinput", "set-prop",
00017                            str(id), "Device Enabled", str(enable)])
00018 
00019 def disableDeviceById(id):
00020     setDeviceEnable(id, 0)
00021 
00022 def enableDeviceById(id):
00023     setDeviceEnable(id, 1)
00024 
00025 def disableDeviceByName(name):
00026     name_id_list = getList()
00027     for device_name, id in name_id_list:
00028         if name == device_name:
00029             disableDeviceByName(id)
00030             
00031 def enableDeviceByName(name):
00032     name_id_list = getList()
00033     for device_name, id in name_id_list:
00034         if name == device_name:
00035             enableDeviceByName(id)
00036 
00037 def disableDeviceByRegexp(regexp):
00038     name_id_list = getList()
00039     for device_name, id in name_id_list:
00040         if re.match(regexp, device_name) is not None:
00041             disableDeviceById(id)
00042 
00043 def enableDeviceByRegexp(regexp):
00044     name_id_list = getList()
00045     for device_name, id in name_id_list:
00046         if re.match(regexp, device_name) is not None:
00047             enableDeviceById(id)


joy_mouse
Author(s):
autogenerated on Fri Apr 19 2019 03:45:21