-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitchmonitor.au3
More file actions
89 lines (72 loc) · 2 KB
/
switchmonitor.au3
File metadata and controls
89 lines (72 loc) · 2 KB
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
#include <WinAPI.au3>
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
HotKeySet("#{PGUP}", "NextMon")
HotKeySet("#{PGDN}", "PrevMon")
TrayCreateEventItem("Next Monitor", "NextMon")
TrayCreateEventItem("Previous Monitor", "PrevMon")
TrayCreateItem("")
$idLockMonitor = TrayCreateEventItem("Lock Monitor", "ToggleLockMonitor")
TrayCreateItem("")
TrayCreateEventItem("Exit", "ExitScript")
Global $lockMonitor = False
Global $monitor = GetMonitor(MouseGetPos(0))
Loop()
Func Loop()
Local $lastUpdated = 0
While 1
If $lockMonitor Then
Local $currentMonitor = GetMonitor(MouseGetPos(0))
If $currentMonitor > $monitor Then
MouseMove(@DesktopWidth * ($monitor + 1) - 1, MouseGetPos(1), 0)
$lastUpdated = TimerInit()
ElseIf $currentMonitor < $monitor Then
MouseMove(@DesktopWidth * $monitor, MouseGetPos(1), 0)
$lastUpdated = TimerInit()
EndIf
EndIf
If TimerDiff($lastUpdated) > 1000 Then
Sleep(100)
EndIf
WEnd
EndFunc
Func ExitScript()
Exit
EndFunc
Func TrayCreateEventItem($text, $function)
Local $id = TrayCreateItem($text)
TrayItemSetOnEvent(-1, $function)
Return $id
EndFunc
Func GetMonitor($mouseX)
Return Floor($mouseX / @DesktopWidth)
EndFunc
Func VirtScreenWidth()
Return _WinAPI_GetSystemMetrics(78)
EndFunc
Func VirtScreenMinX()
Return _WinAPI_GetSystemMetrics(76)
EndFunc
Func VirtScreenMaxX()
Return VirtScreenMinX() + VirtScreenWidth()
EndFunc
Func NextMon()
Local $newX = MouseGetPos(0) + @DesktopWidth
If $newX <= VirtScreenMaxX() Then
MouseMove($newX, MouseGetPos(1),0)
$monitor = GetMonitor(MouseGetPos(0))
EndIf
EndFunc
Func PrevMon()
Local $newX = MouseGetPos(0) - @DesktopWidth
if $newX >= VirtScreenMinX() Then
MouseMove($newX, MouseGetPos(1),0)
$monitor = GetMonitor(MouseGetPos(0))
EndIf
EndFunc
Func ToggleLockMonitor()
$lockMonitor = Not($lockMonitor)
$monitor = GetMonitor(MouseGetPos(0))
TrayItemSetState($idLockMonitor, 1 + Not($lockMonitor) * 3)
EndFunc