forked from nishtha981/hand-gesture-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhand_position.py
57 lines (50 loc) · 1.66 KB
/
hand_position.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
import time
import pyautogui
def detect_hand_position(x, y, scrw, scrh):
leftarea = (0, 0, scrw // 2, scrh // 2)
uparea = (0, 0, scrw // 2, scrh // 2)
downarea = (scrw // 2, scrh // 2, scrw, scrh)
rightarea = (scrw // 2, scrh // 2, scrw, scrh)
if x < leftarea[2] and y > leftarea[1]:
return 'left'
elif x < uparea[2] and y < uparea[3]:
return 'up'
elif x > downarea[0] and y > downarea[1]:
return 'down'
elif x > rightarea[0] and y < rightarea[3]:
return 'right'
else:
return None
def stimulate_keys():
scrw, scrh = pyautogui.size()
while True:
x, y = pyautogui.position()
hand_position = detect_hand_position(x, y, scrw, scrh)
if hand_position == 'left':
pyautogui.keyDown('left')
pyautogui.keyUp('right')
pyautogui.keyUp('up')
pyautogui.keyUp('down')
elif hand_position == 'up':
pyautogui.keyDown('up')
pyautogui.keyUp('down')
pyautogui.keyUp('left')
pyautogui.keyUp('right')
elif hand_position == 'down':
pyautogui.keyDown('down')
pyautogui.keyUp('up')
pyautogui.keyUp('left')
pyautogui.keyUp('right')
elif hand_position == 'right':
pyautogui.keyDown('right')
pyautogui.keyUp('left')
pyautogui.keyUp('up')
pyautogui.keyUp('down')
else:
pyautogui.keyUp('left')
pyautogui.keyUp('up')
pyautogui.keyUp('down')
pyautogui.keyUp('right')
time.sleep(0.1)
if __name__ == "_main_":
stimulate_keys()