Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import subprocess
- import time
- class threeFingers:
- def __init__(self, x, y):
- self.start_x = x
- self.start_y = y
- def endGesture(self, x, y, f):
- if not f==3:
- diff_x = x-self.start_x
- print diff_x
- diff_y = y-self.start_y
- if diff_x > 100:
- os.system("xdotool key a")
- elif diff_x < -100:
- os.system("xdotool key b")
- return True
- else:
- return False
- class fourFingers:
- def __init__(self, x, y):
- self.start_x = x
- self.start_y = y
- def endGesture(self, x, y, f):
- if not f==4:
- diff_x = x-self.start_x
- diff_y = y-self.start_y
- if diff_x > 100:
- os.system("xdotool key c")
- elif diff_x < -100:
- os.system("xdotool key d")
- return True
- else:
- return False
- if __name__ == "__main__":
- cmd = 'synclient -m 100'
- p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell = True)
- skip = False
- first = True
- start = False
- start_x = 0
- start_y = 0
- diff_x = 0
- diff_y = 0
- timeStart = 0
- timeEnd = 0
- threeF = None
- fourF = None
- finger3 = False
- finger4 = False
- try:
- while True:
- line = p.stdout.readline()
- if not line:
- break
- try:
- tokens = [x for x in re.split('([^0-9\.])+', line.strip()) if x.strip()]
- x, y, fingers = int(tokens[1]), int(tokens[2]), int(tokens[4])
- if not start:
- if fingers==3:
- threeF = threeFingers(x, y)
- start = True
- finger3 = True
- timeStart = time.time()
- elif fingers==4:
- fourF = fourFingers(x, y)
- start = True
- finger4 = True
- timeStart = time.time()
- if start:
- #Gestures have a timeout
- if time.time()-timeStart>0.37:
- start = False
- threeF = None
- fourF = None
- finger3 = False
- finger4 = False
- else:
- if finger3:
- if threeF.endGesture(x, y, fingers):
- threeF = None
- finger3 = False
- start = False
- elif finger4:
- if fourF.endGesture(x, y, fingers):
- fourF = None
- finger4 = False
- start = False
- except (IndexError, ValueError):
- pass
- except KeyboardInterrupt:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement