-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLeapDJ.py
172 lines (116 loc) · 4.45 KB
/
LeapDJ.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import Leap, sys, thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
from pynput.keyboard import Key, Controller
from time import sleep
class LeapMotionListener(Leap.Listener):
finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE_INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
def on_init(self, controller):
print ("Initialized")
def on_connect(self, controller):
print ("Motion Sensor Connected")
controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP);
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
def on_disconnect(self, controller):
print ("Motion Sensor Disconnected")
def on_exit(self, controller):
print ("Exited")
def on_frame(self, controller):
frame = controller.frame()
keyboard1 = Controller()
"""print "frame ID: " + str(frame.id) \
+ " Timestamp: " + str(frame.timestamp) \
+ " Number of Hands " + str(len(frame.hands)) \
+ " Number of Fingers " + str(len(frame.fingers)) \
+ " Number of Tools " + str(len(frame.tools)) \
+ " Number of Gestures " + str(len(frame.gestures()))"""
for hand in frame.hands:
handType = 'Left Hand' if hand.is_left else 'Right Hand'
print handType + ' Hand ID:' + str(hand.id) + "Palm Position" + str(hand.palm_position)
print( "Number of Gestures " + str(len(frame.gestures())))
print()
print str(hand.palm_position.y)
normal = hand.palm_normal
direction = hand.direction
pitchValue = hand.palm_position.y
hold = 0
time.sleep(.1)
if(hold ==0):
if(pitchValue < 100):
altTab()
playPause()
altTab()
hold = 1
if (hold ==1):
hold = 0
if(pitchValue >300):
altTab()
time.sleep(1)
keyboard1.press('g')
keyboard1.release('g')
time.sleep(1)
altTab()
"""
hold = 0
if hold == 0:
if((pitchValue < 100)):
keyboard1.press('H')
keyboard1.release('H')
#altTab()
print('h')
hold = 1
if hold == 1:
if((pitchValue > 100)):
# altTab()
print('h')
keyboard1.press('H')
keyboard1.release('H')
hold = 0
"""
# print "Pitch:" + str(direction.pitch * Leap.RAD_TO_DEG) + ' Roll: ' +str(normal.roll * Leap.RAD_TO_DEG) + ' Yaw: '+ str(direction.yaw * Leap.RAD_TO_DEG)
"""
arm = hand.arm
print "Arm Direct: " + str(arm.direction) + ' Wrist Position:' + str(arm.wrist_position) + " Elbow: " + str(arm.elbow_position)
for finger in hand.fingers:
print "Finger Type: " + self.finger_names[finger.Type()]
for gesture in frame.gestures():
if gesture.type == Leap.Gesture.TYPE_SCREEN_TAP:
screentap = ScreenTapGesture(gesture)
print "Screen Tap ID: "
time.sleep(2)
scrnID = str(gesture.id)
if(scrnID > 0):
keyboard.press(Key.space)
keyboard.release(Key.space)
"""
def altTab():
keyboard = Controller()
keyboard.press(Key.cmd) #Alt
sleep(.3)
keyboard.press(Key.tab) #Tab
sleep(.3)
keyboard.release(Key.tab) #~Tab
sleep(.3)
keyboard.release(Key.cmd) #~Alt
def playPause():
keyboard1 = Controller()
time.sleep(.3)
keyboard1.press('p')
keyboard1.release('p')
time.sleep(.3)
def main():
listener = LeapMotionListener()
controller = Leap.Controller()
controller.add_listener(listener)
print ("Press Enter to Quit")
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
controller.remove_listener(listener)
if __name__ == "__main__":
main()