-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyobswitching.py
79 lines (61 loc) · 2.01 KB
/
pyobswitching.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
import sys
import pyautogui as pyauto
import screeninfo
from infi.systray import SysTrayIcon
class Screen:
def create(self, key, n, x, y, w, h):
self.key = key
self.n = n
self.x = x
self.y = y
self.w = w
self.h = h
def from_monitor(self, key, mon):
self.key = key
self.x = mon.x
self.y = mon.y
self.w = mon.width
self.h = mon.height
self.n = int(mon.name[-1:])
def main():
print("caca")
key_combo = ""
curr_screen = 1
screens = []
monitors = screeninfo.get_monitors()
for i in range(len(monitors)):
screen = Screen()
screen.from_monitor(sys.argv[i+1], monitors[i])
screens.append(screen)
for i in range(len(sys.argv) - len(monitors) - 1):
key_combo += "'" + sys.argv[len(monitors)+i+1] + "',"
print(key_combo)
#Checking for the screen the maouse is at at the beginning
mouse_pos = pyauto.position()
for screen in screens:
if bounds(mouse_pos.x, mouse_pos.y, screen.x, screen.y, screen.w, screen.h):
curr_screen = screen.n
to_exec = "press_combo(" + key_combo + "'" + screen.key + "')"
print(to_exec)
exec(to_exec)
while True:
mouse_pos = pyauto.position()
for screen in screens:
if bounds(mouse_pos.x, mouse_pos.y, screen.x, screen.y, screen.w, screen.h):
if screen.n != curr_screen:
print("swaped screens")
curr_screen = screen.n
to_exec = "press_combo(" + key_combo + "'" + screen.key + "')"
exec(to_exec)
#def on_mouse_move(x, y):
def press_combo(*keys):
for key in keys:
pyauto.keyDown(key)
for key in keys:
pyauto.keyUp(key)
def bounds(mx, my, x, y, w, h):
return mx > x and mx < x+w and my > y and my < y+h
menu_options = ((None, None, main),)
systray = SysTrayIcon("", "PyOBSwitching", menu_options)
systray.start()
main()