-
Notifications
You must be signed in to change notification settings - Fork 0
/
determine_action.py
138 lines (108 loc) · 4.55 KB
/
determine_action.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
import pyautogui
class actionHandler:
def __init__(self, overlayGui):
self.mode = "Zoom"
self.lastFrameGesture = None
self.isGuiOpen = False
self.actions = {
"Zoom": {
"horizontal-flap+horizontal-flap": self.zoom_in,
"vertical-flap+vertical-flap": self.zoom_out
},
"Switch Tab": {
"horizontal-flap+horizontal-flap": self.browser_switch_tab
},
"Switch Window": {
"horizontal-flap+horizontal-flap": self.switch_window,
"pinch+pinch": self.select
},
"Element Select": {
"horizontal-flap+horizontal-flap": self.tab_forward,
"vertical-flap+vertical-flap": self.tab_backwards,
"pinch+pinch": self.select,
"point-up+point-up": self.escape
},
"Scroll": {
"vertical-flap+vertical-flap": self.scroll_up,
"horizontal-flap+horizontal-flap": self.scroll_down
},
"Arrow Keys": {
"point-up+point-up": self.arrow_up,
"point-down+point-down": self.arrow_down,
"point-left+point-left": self.arrow_left,
"point-right+point-right": self.arrow_right
}
}
def handle_action(self, gesture, overlayGui):
"""
Handles the action based on the gesture provided.
Parameters:
gesture (str): The gesture to handle.
overlayGui (ModeSwitchGui): The mode switcher GUI.
"""
if gesture is not None:
self.handle_gui(gesture, overlayGui)
if not self.isGuiOpen and self.lastFrameGesture is not None:
action = self.encode_gesture(gesture)
if self.mode in self.actions and action in self.actions[self.mode]:
print(action)
self.actions[self.mode][action]()
self.lastFrameGesture = gesture
def encode_gesture(self, gesture):
"""
Encodes the gesture to be used in the actions dictionary.
Parameters:
gesture (str): The gesture to encode.
Returns:
str: The encoded gesture.
"""
return self.lastFrameGesture + "+" + gesture
def handle_gui(self, gesture, overlayGui):
"""
Handles the GUI based on the gesture provided.
Parameters:
gesture (str): The gesture to handle.
overlayGui (ModeSwitchGui): The mode switcher GUI.
"""
if gesture == "fist" and self.lastFrameGesture != "fist":
if not self.isGuiOpen:
self.isGuiOpen = True
overlayGui.createGui()
overlayGui.updateGui()
elif self.isGuiOpen:
overlayGui.destroyGUI()
self.isGuiOpen = False
elif self.isGuiOpen and gesture == "pinch":
self.mode = overlayGui.switchSelection()
overlayGui.updateGui()
"""
The following functions are the actions that can be performed based on the gesture.
"""
def zoom_in(self):
pyautogui.hotkey('ctrl', '+')
def zoom_out(self):
pyautogui.hotkey('ctrl', '-')
def browser_switch_tab(self):
pyautogui.hotkey('ctrl', 'tab')
def switch_window(self):
pyautogui.hotkey('ctrl', 'alt', 'tab')
def tab_forward(self):
pyautogui.hotkey('tab')
def tab_backwards(self):
pyautogui.hotkey('shift', 'tab')
def select(self):
pyautogui.hotkey('enter')
def scroll_up(self):
pyautogui.scroll(300)
def scroll_down(self):
pyautogui.scroll(-300)
def escape(self):
pyautogui.hotkey('esc')
def arrow_up(self):
pyautogui.press('up')
def arrow_down(self):
pyautogui.press('down')
def arrow_left(self):
pyautogui.press('left')
def arrow_right(self):
pyautogui.press('right')