def xinput_set(targets, prop, value, type="float"): if SIMULATE: return for target in get_active_targets().intersection(targets): print 'xinput: %s=%r (%s) on %s' % (prop, value, type, target) xinput('set-prop', target, prop, value, type=type)
def key_counter(counter, keyboard_id): def incr_counter(line): if "press" in line: counter.value += 1 try: sh.xinput('test', keyboard_id, _out=incr_counter).wait() except KeyboardInterrupt: logger.info("Stopping key-counter process.")
def find_device_ids(self): """ :return: list of all device ids from xinput, excluding XTEST devices. """ device_info = str(sh.xinput('list', '--short')) id_pattern = r'id=(\d+)' xtest_id_pattern = r'XTEST[^\n]+id=(\d+)' device_ids = list(set(re.findall(id_pattern, device_info)).difference( set(re.findall(xtest_id_pattern, device_info)))) return device_ids
def find_device_ids(self): """ :return: list of all device ids from xinput, excluding XTEST devices. """ device_info = str(sh.xinput('list', '--short')) id_pattern = r'id=(\d+)' xtest_id_pattern = r'XTEST[^\n]+id=(\d+)' device_ids = list( set(re.findall(id_pattern, device_info)).difference( set(re.findall(xtest_id_pattern, device_info)))) return device_ids
#!/usr/bin/python3 import sh import re xinputstring = str(sh.xinput(list=True)) ids = re.findall('USB\sLaser\sGame\sMouse\s+id=[0-9]+', xinputstring) for mouseid in ids: avariable = re.search('id=[0-9]+', mouseid).group()[3::] listofproperties = str(sh.xinput("list-props", avariable)) if re.search('Device\sAccel\sProfile', listofproperties): sh.xinput("set-prop", avariable, 'Device Accel Profile', "-1") sh.xinput("set-prop", avariable, 'Device Accel Velocity Scaling', "1") sh.xinput("set-prop", avariable, 'Device Accel Constant Deceleration', "7")
import sh str = sh.xinput() str = str.split('\n') id = '-1' for line in str: if (line.find('Touchpad') + 1): id = line.split('\t')[1].split('=')[1] break if (id == '-1'): print('Not Found Touchpad!') exit() str = sh.xinput('list-props', id) str = str.split('\n') str = str[1].split(':\t') state = int(str[1]) if (state): sh.xinput('--disable', id) else: sh.xinput('--enable', id)