-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcornerTriggers.py
49 lines (32 loc) · 1.28 KB
/
cornerTriggers.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
import pyautogui
from pynput.keyboard import Controller , Key
import time
keyboard = Controller()
CORNER_THRESHOLD = 10
def trigger_hotkey(hotkey):
if hotkey == "tab":
hotkey = Key.tab
elif hotkey == "d":
hotkey = "d"
with keyboard.pressed(Key.cmd):
keyboard.press(hotkey)
keyboard.release(hotkey)
def callback(action):
if action == "upper_left":
trigger_hotkey("tab")
elif action == "lower_left":
trigger_hotkey("d")
def monitor_cursor(stop_flag):
avoid_repeated_triggers = True
while not stop_flag['isRunning']:
x, y = pyautogui.position()
screen_width, screen_height = pyautogui.size()
if x <= CORNER_THRESHOLD and y <= CORNER_THRESHOLD and avoid_repeated_triggers:
callback("upper_left")
avoid_repeated_triggers = False
elif x <= CORNER_THRESHOLD and y >= screen_height - CORNER_THRESHOLD and avoid_repeated_triggers:
callback("lower_left")
avoid_repeated_triggers = False
elif not (x <= CORNER_THRESHOLD and y <= CORNER_THRESHOLD) and not (x <= CORNER_THRESHOLD and y >= screen_height - CORNER_THRESHOLD) and not avoid_repeated_triggers:
avoid_repeated_triggers = True
time.sleep(0.1)