-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.ahk
More file actions
195 lines (179 loc) · 5.74 KB
/
script.ahk
File metadata and controls
195 lines (179 loc) · 5.74 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
SetTitleMatchMode, 2 ; matches partial window titles
;SingleInstance Force
EnvGet, ZOOM_ID, "ZOOM_ID"
EnvGet, PRIVATE_LESSONS_CALENDAR_ID, "PRIVATE_LESSONS_CALENDAR_ID"
; Took from https://www.autohotkey.com/board/topic/54030-resolved-activate-last-active-window-what-is-wrong/
previous_ID := 0
loop
{
; get the current window's handle
WinGet, current_ID, ID, A
; wait until a new window is activated
WinWaitNotActive, ahk_id %current_ID%
; save the previous window's handle for later
previous_ID := current_ID
}
RoA(WinTitle, Target) { ; RoA means "RunOrActivate"
IfWinExist, %WinTitle%
WinActivate, %WinTitle%
else
Run, %Target%
}
; ---------------------------------------------------------------
; Bindings
; ---------------------------------------------------------------
!p::
WinGetTitle, Title, A
MsgBox, The active window is "%Title%".
Return
!a::RoA("Doom Emacs@nixos", "")
!b::RoA("Thunderbird", "C:\Program Files\Mozilla Thunderbird\thunderbird.exe")
!c::RoA("Obsidian", "")
!d::
WinActivate, ahk_id %WinTag%
return
!e::RoA("Telegram", "C:\Users\monte\AppData\Roaming\Telegram Desktop\Telegram.exe")
!f::RoA("Discord", "C:\Users\monte\AppData\Local\Discord\Update.exe --processStart Discord.exe")
!g::RoA("Webex", "C:\Users\monte\AppData\Local\Programs\Cisco Spark\CiscoCollabHost.exe")
!m::
WinMinimize, A
return
!q::
Run, Explorer D:\
return
!r::RoA("Slack", "C:\Users\monte\AppData\Local\slack\slack.exe")
!s::RoA("Alacritty", "C:\Users\monte\Desktop\bin\Alacritty-v0.10.0-portable.exe")
!t::
WinTag := WinActive("A")
Return
!v::RoA("lazywithclass - Anki", "C:\Users\monte\AppData\Local\Programs\Anki\anki.exe")
!w::
WinActivate, WhatsApp
return
!z::
WinActivate, Zoom Meeting
return
;// prevent from accidentally closing windows
$^w::
IfWinActive Telegram
return
IfWinActive mpv
return
Send ^w
return
!1::
Run, %A_Desktop%
return
!2::
Run, %A_MyDocuments%\..\Documents
return
!3::
Run, %A_MyDocuments%\..\Downloads
return
!+z::
; prev_clipboard := clipboard
content = https://us02web.zoom.us/j/%ZOOM_ID%
clipboard := content
ClipWait ; Wait for the clipboard to contain text.
ClipWait
Send ^v
; clipboard := prev_clipboard
return
!+^z::
prev_clipboard := clipboard
content = https://calendar.app.google/%PRIVATE_LESSONS_CALENDAR_ID%
clipboard := content
ClipWait ; Wait for the clipboard to contain text.
Send ^v
clipboard := prev_clipboard
return
F1::
WinActivate ahk_id %previous_ID%
return
~LShift::RapidHotkey("{F1}", 2)
; ---------------------------------------------------------------
; Functions
; ---------------------------------------------------------------
; Took from https://www.autohotkey.com/board/topic/35566-rapidhotkey/
RapidHotkey(keystroke, times="2", delay=0.2, IsLabel=0)
{
Pattern := Morse(delay*1000)
If (StrLen(Pattern) < 2 and Chr(Asc(times)) != "1")
Return
If (times = "" and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+1)
continue := A_Index, times := StrLen(Pattern)
}
Else if (RegExMatch(times, "^\d+$") and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+times-1)
times := StrLen(Pattern), continue := A_Index
}
Else if InStr(times, """")
{
Loop, Parse, times,""
If (StrLen(Pattern) = A_LoopField)
continue := A_Index, times := A_LoopField
}
Else if (times = "")
continue := 1, times := 2
Else if (times = StrLen(Pattern))
continue = 1
If !continue
Return
Loop, Parse, keystroke,""
If (continue = A_Index)
keystr := A_LoopField
Loop, Parse, IsLabel,""
If (continue = A_Index)
IsLabel := A_LoopField
hotkey := RegExReplace(A_ThisHotkey, "[\*\~\$\#\+\!\^]")
IfInString, hotkey, %A_Space%
StringTrimLeft, hotkey,hotkey,% InStr(hotkey,A_Space,1,0)
backspace := "{BS " times "}"
keywait = Ctrl|Alt|Shift|LWin|RWin
Loop, Parse, keywait, |
KeyWait, %A_LoopField%
If ((!IsLabel or (IsLabel and IsLabel(keystr))) and InStr(A_ThisHotkey, "~") and !RegExMatch(A_ThisHotkey
, "i)\^[^\!\d]|![^\d]|#|Control|Ctrl|LCtrl|RCtrl|Shift|RShift|LShift|RWin|LWin|Alt|LAlt|RAlt|Escape|BackSpace|F\d\d?|"
. "Insert|Esc|Escape|BS|Delete|Home|End|PgDn|PgUp|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|AppsKey|"
. "PrintScreen|CtrlDown|Pause|Break|Help|Sleep|Browser_Back|Browser_Forward|Browser_Refresh|Browser_Stop|"
. "Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|MButton|RButton|LButton|"
. "Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2"))
Send % backspace
If (WinExist("AHK_class #32768") and hotkey = "RButton")
WinClose, AHK_class #32768
If !IsLabel
Send % keystr
else if IsLabel(keystr)
Gosub, %keystr%
Return
}
Morse(timeout = 400) { ;by Laszo -> http://www.autohotkey.com/forum/viewtopic.php?t=16951 (Modified to return: KeyWait %key%, T%tout%)
tout := timeout/1000
key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
IfInString, key, %A_Space%
StringTrimLeft, key, key,% InStr(key,A_Space,1,0)
If Key in Shift,Win,Ctrl,Alt
key1:="{L" key "}{R" key "}"
Loop {
t := A_TickCount
KeyWait %key%, T%tout%
Pattern .= A_TickCount-t > timeout
If(ErrorLevel)
Return Pattern
If key in Capslock,LButton,RButton,MButton,ScrollLock,CapsLock,NumLock
KeyWait,%key%,T%tout% D
else if Asc(A_ThisHotkey)=36
KeyWait,%key%,T%tout% D
else
Input,pressed,T%tout% L1 V,{%key%}%key1%
If (ErrorLevel="Timeout" or ErrorLevel=1)
Return Pattern
else if (ErrorLevel="Max")
Return
}
}