-
Notifications
You must be signed in to change notification settings - Fork 65
/
PyLeapMouse.py
executable file
·72 lines (61 loc) · 2.68 KB
/
PyLeapMouse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#William Yager
#Leap Python mouse controller POC
import sys
from leap import Leap, Mouse
from PalmControl import Palm_Control_Listener #For palm-tilt based control
from FingerControl import Finger_Control_Listener #For finger-pointing control
from MotionControl import Motion_Control_Listener #For motion control
def show_help():
print "----------------------------------PyLeapMouse----------------------------------"
print "Use --finger (or blank) for pointer finger control, and --palm for palm control."
print "Set smooth aggressiveness (# samples) with \"--smooth-aggressiveness [# samples]\""
print "Set smooth falloff with \"--smooth-falloff [% per sample]\""
print "Read README.md for even more info.\n"
def main():
if "-h" in sys.argv or "--help" in sys.argv:
show_help()
return
print "----------------------------------PyLeapMouse----------------------------------"
print "Use --finger (or blank) for pointer finger control, and --palm for palm control."
print "Use -h or --help for more info.\n"
#Default
finger_mode = True
palm_mode = False
motion_mode = False
smooth_aggressiveness = 8
smooth_falloff = 1.3
for i in range(0,len(sys.argv)):
arg = sys.argv[i].lower()
if "--palm" in arg:
finger_mode = False
palm_mode = True
motion_mode = False
if "--motion" in arg:
finger_mode = False
palm_mode = False
motion_mode = True
if "--smooth-falloff" in arg:
smooth_falloff = float(sys.argv[i+1])
if "--smooth-aggressiveness" in arg:
smooth_aggressiveness = int(sys.argv[i+1])
listener = None; #I'm tired and can't think of a way to organize this segment nicely
#Create a custom listener object which controls the mouse
if finger_mode: #Finger pointer mode
listener = Finger_Control_Listener(Mouse, smooth_aggressiveness=smooth_aggressiveness, smooth_falloff=smooth_falloff)
print "Using finger mode..."
elif palm_mode: #Palm control mode
listener = Palm_Control_Listener(Mouse)
print "Using palm mode..."
elif motion_mode: #Motion control mode
listener = Motion_Control_Listener(Mouse)
print "Using motion mode..."
controller = Leap.Controller() #Get a Leap controller
controller.set_policy_flags(Leap.Controller.POLICY_BACKGROUND_FRAMES)
print "Adding Listener."
controller.add_listener(listener) #Attach the listener
#Keep this process running until Enter is pressed
print "Press Enter to quit..."
sys.stdin.readline()
#Remove the sample listener when done
controller.remove_listener(listener)
main()