-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathahk_scripts.ahk
More file actions
427 lines (344 loc) · 14.1 KB
/
Copy pathahk_scripts.ahk
File metadata and controls
427 lines (344 loc) · 14.1 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
; ================================================================================
; # countdown.ahk
; ================================================================================
^F3:: {
SetT := InputBox('How long from now? (minutes)', 'w250 h100').value * 60
MyGui := Gui('+AlwaysOnTop -Caption -Border -SysMenu +ToolWindow', 'Sleep Time Left')
MyGui.MarginX := 2
MyGui.MarginY := 0
MyGui.SetFont('s24 bold', 'Verdana')
MyGui.TX := MyGui.AddText('x2 y6 h40 cGreen Center', Frmt(MyGui.initSecs := SetT))
MyGui.TX.OnEvent('Click', (*) => PostMessage(0xA1, 2,,, 'A'))
MyGui.Progress1 := MyGui.AddProgress('x0 y0 wp h5 -Smooth Range0-' SetT ' vProgress1', MyGui.ProgNum := SetT)
Cuar := Floor(SetT/4)
MyGui.Cuar1 := Cuar*1
MyGui.Cuar2 := Cuar*2
MyGui.Cuar3 := Cuar*3
MyGui.TX.SetFont('s23')
MyGui.Show
MyGui.Progress1.GetPos(,, &w)
MyGui.Progress1.Move(,, w+MyGui.MarginX*2)
; start countdown
SetTimer(SubtractTime, 1000)
SubtractTime()
{
MyGui.Progress1.value-- ; subtract one tick from progress bar
MyGui.TX.Value := Frmt(--MyGui.initSecs) ; update time
if MyGui.TX.Value = '00:00' { ; if time is up
Sleep(1000) ; wait one more second
SetTimer(SubtractTime, 0) ; stop countdown timer
MyGui.Destroy() ; destroy gui
return Msgbox("End of countdown!", 'Reminder', '64') ; show reminder message
}
switch MyGui.initSecs
{
case MyGui.Cuar2:
MyGui.TX.SetFont('s24 cFFA500')
MyGui.Progress1.Opt('cFFA500')
case MyGui.Cuar1:
MyGui.TX.SetFont('s24 cRed')
MyGui.Progress1.Opt('cRed')
}
}
Frmt(secs)
{
time := 20000101
time := DateAdd(time, secs, 'Seconds')
mmss := FormatTime(time, (secs < 3600 ? 'mm:ss' : 'HH:mm:ss'))
return mmss
}
}
; ================================================================================
; # g915_n.ahk
; ================================================================================
; Fix repeating key problem with Logitech G915
; https://stackoverflow.com/questions/68349486/how-to-make-an-autohotkey-script-to-fix-my-keyboard-repeating-key-problem
*n:: ; When 'n' is pressed (with or without modifiers like `Shift` or `Alt`)
{
Send("{Blind}n") ; Send 'n' blindly to the computer
Sleep(100) ; Then delay for a duration of one second [change to taste]
return
}
; ================================================================================
; # kb_shcut.ahk
; ================================================================================
; Print current date
:*:!date::
{
CurrentDateTime := FormatTime(, "dddd, yyyy-MM-dd")
SendInput(CurrentDateTime)
return
}
; Print current time
:*:!time::
{
CurrentDateTime := FormatTime(, "HH:mm:ss")
SendInput(CurrentDateTime)
return
}
; Open Google Calendar
:*:!gc::
{
Run "firefox.exe https://calendar.google.com/calendar/u/0/"
return
}
; ================================================================================
; # mouse_move.ahk
; ================================================================================
n := 10 ; number of intervals
w := A_ScreenWidth / n
move_5px()
{
MouseGetPos(&xpos, &ypos)
MouseMove(-5, 0, 10, "R")
Sleep(100)
}
^M:: {
SetTimer(move_5px, 1000)
}
; ================================================================================
; # procs.ahk
; ================================================================================
^!Up:: {
procs := ['turtl.exe', 'Spotify.exe', 'firefox.exe', 'DiscordCanary.exe', 'Routine.exe', 'Antidote.exe', 'slack.exe', 'Spike.exe', 'Telegram.exe', 'KeePass.exe']
DoProcs(*) {
Input := MyInput.Text
if (Input = "close") {
CloseProcs()
OpenCloseGui.Hide
} else if (Input = "open") {
RunProcs()
OpenCloseGui.Hide
} else {
MsgBox("Invalid input. Need 'open' or 'close'")
}
return
}
CloseProcs(*) {
for p in procs
if (PID := ProcessExist(p)) {
ProcessClose(PID)
}
return
}
RunProcs(*) {
for p in procs
if (!PID := ProcessExist(p)) {
Run "shell:startup" p
}
return
}
OpenCloseGui := Gui('+ToolWindow', 'Open/Close')
MyInput := OpenCloseGui.AddEdit("vInputField")
MyBtn := OpenCloseGui.AddButton("Default w80", "OK")
MyBtn.OnEvent("Click", DoProcs)
OpenCloseGui.Show
}
; ================================================================================
; # run_hotkeys.ahk
; ================================================================================
#C::
{
Run "C:\Program Files\PowerShell\7\pwsh.exe"
}
; ================================================================================
; # setontop.ahk
; ================================================================================
^SPACE::WinSetAlwaysOnTop -1, "A"
; ================================================================================
; # typing_hotkeys.ahk
; ================================================================================
; Note: these hotkeys were designed with the French AZERTY keyboard layout in mind.
^!Space::Send("{U+00A0}") ; CTRL + ALT + Space = non-breaking space (nbsp)
^!SC00A::Send("{U+00C7}") ; CTRL + ALT + ç = uppercase C-cedilla (Ç)
^SC00B::Send("{U+00C0}") ; CTRL + à = uppercase A with grave accent (À)
^!SC008::Send("{U+00C8}") ; CTRL + ALT + è = uppercase E with grave accent (È)
^!SC003::Send("{U+00C9}") ; CTRL + ALT + é = uppercase E with acute accent (É)
^<!SC032::Send("{U+00A0}{U+003F}") ; CTRL + ALT + , = nbsp + question mark
^<!SC035::Send("{U+00A0}{U+0021}") ; CTRL + ALT + ! = nbsp + exclamation mark
^<!SC033::Send("{U+00A0}{U+003B}{U+0020}") ; CTRL + ALT + ; = nbsp + semicolon + normal space
^<!SC034::Send("{U+00A0}{U+003A}{U+0020}") ; CTRL + ALT + : = nbsp + colon + normal space
^!SC056::Send("{U+00AB}{U+00A0}") ; CTRL + ALT + < = French opening quotation mark + nbsp
^SC056::Send("{U+00A0}{U+00BB}") ; CTRL + < = nbsp + French closing quotation mark
^<!SC02D::Send("{U+00A0}{U+00D7}{U+00A0}") ; CTRL + ALT + x = nbsp + multiplication sign + nbsp
^SC04A::Send("{U+2013}") ; CTRL + - (Numpad) = en-dash (–)
^<!SC04A::Send("{U+2014}") ; CTRL + ALT + - (Numpad) = em-dash (—)
<+SC04A::Send("{U+2212}") ; RShift + - (Numpad) = minus sign (−)
<!SC009::Send("{U+005C}") ; ALT + _ = backslash (\)
<!SC033::Send("{U+00B7}") ; ALT + ; = interpunct (·)
<!SC008::Send("{U+0060}") ; ALT + è = backtick (`)
<!SC003::Send("{U+007E}") ; ALT + é = tilde (~)
>+SC00C::Send("{U+00BA}") ; RShift + ) = ordinal indicator (º)
!SC012::Send("{U+1D49}") ; ALT + e = superscript e (ᵉ)
!SC013::Send("{U+02B3}") ; ALT + r = superscript r (ʳ)
:*:!oe::{U+0153} ; exclamation mark + oe = œ
:*:...::{U+2026} ; 3 full stops = ellipsis as 1 character (…)
:*:->::{U+2192} ; hyphen + > = right arrow (→)
; ================================================================================
; # uncopy_newlines.ahk
; ================================================================================
^+C:: {
Suspend(1)
A_Clipboard := ""
Send "^c"
ClipWait(50)
A_Clipboard := RegExReplace(A_Clipboard, "(\R)", " ")
Suspend(0)
return
}
; ================================================================================
; # audio_switch.ahk
; ================================================================================
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=49980&p=387886#p387886
speakersName := "Speakers (Realtek(R) Audio)"
headphonesName := "Headphones (KT USB Audio)"
List := EnumAudioEndpoints()
Devices := ""
for Device in List
Devices .= Format("{} ({})`n`n", Device["Name"], Device["ID"])
; for debugging
;MsgBox(Devices)
^SC130::
{
SetDefaultEndpoint(GetDeviceID(List, speakersName))
ShowIndicator(speakersName)
}
+SC130::
{
SetDefaultEndpoint(GetDeviceID(List, headphonesName))
ShowIndicator(headphonesName)
}
; --- Indicator GUI ---
ShowIndicator(text) {
g := Gui("+AlwaysOnTop -Caption +ToolWindow +Border")
g.BackColor := "White"
g.SetFont("s12 bold", "Segoe UI")
g.AddText("Center w200 h60", text)
; Position centered at bottom
screenW := A_ScreenWidth
screenH := A_ScreenHeight
winW := 220
winH := 90
x := (screenW - winW) // 2
y := screenH - winH - 60
g.Show("x" x " y" y " w" winW " h" winH " NA")
SetTimer(() => g.Destroy(), -1500)
}
/*
Generates a collection of audio endpoint devices that meet the specified criteria.
Parameters:
DataFlow:
The data-flow direction for the endpoint devices in the collection.
0 Audio rendering stream. Audio data flows from the application to the audio endpoint device, which renders the stream.
1 Audio capture stream. Audio data flows from the audio endpoint device that captures the stream, to the application.
2 Audio rendering or capture stream. Audio data can flow either from the application to the audio endpoint device, or from the audio endpoint device to the application.
StateMask:
The state or states of the endpoints that are to be included in the collection.
1 Active. The audio adapter that connects to the endpoint device is present and enabled. In addition, if the endpoint device plugs into a jack on the adapter, then the endpoint device is plugged in.
2 Disabled. The user has disabled the device in the Windows multimedia control panel (Mmsys.cpl).
4 Not present. The audio adapter that connects to the endpoint device has been removed or disabled.
8 Unplugged. The audio adapter that contains the jack for the endpoint device is present and enabled, but the endpoint device is not plugged into the jack. Only a device with jack-presence detection can be in this state.
Return value:
Returns an array of Map objects with the following keys:
ID Endpoint ID string that identifies the audio endpoint device.
Name The friendly name of the endpoint device.
*/
EnumAudioEndpoints(DataFlow := 2, StateMask := 1)
{
List := []
; IMMDeviceEnumerator interface.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nn-mmdeviceapi-immdeviceenumerator
IMMDeviceEnumerator := ComObject("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
; IMMDeviceEnumerator::EnumAudioEndpoints method.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdeviceenumerator-enumaudioendpoints
ComCall(3, IMMDeviceEnumerator, "UInt", DataFlow, "UInt", StateMask, "UPtrP", &IMMDeviceCollection:=0)
; IMMDeviceCollection::GetCount method.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevicecollection-getcount
ComCall(3, IMMDeviceCollection, "UIntP", &DevCount:=0) ; Retrieves a count of the devices in the device collection.
loop DevCount
{
List.Push(Device := Map())
; IMMDeviceCollection::Item method.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevicecollection-item
ComCall(4, IMMDeviceCollection, "UInt", A_Index-1, "UPtrP", &IMMDevice:=0)
; IMMDevice::GetId method.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevice-getid
ComCall(5, IMMDevice, "PtrP", &pBuffer:=0)
Device["ID"] := StrGet(pBuffer)
DllCall("Ole32.dll\CoTaskMemFree", "UPtr", pBuffer)
; MMDevice::OpenPropertyStore method.
; https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevice-openpropertystore
ComCall(4, IMMDevice, "UInt", 0x00000000, "UPtrP", &IPropertyStore:=0)
Device["Name"] := GetDeviceProp(IPropertyStore, "{A45C254E-DF1C-4EFD-8020-67D146A850E0}", 14)
ObjRelease(IPropertyStore)
ObjRelease(IMMDevice)
}
ObjRelease(IMMDeviceCollection)
return List
}
/*
Set default audio render endpoint.
Role:
0x1 Default Device.
0x2 Default Communication Device.
*/
SetDefaultEndpoint(DeviceID, Role := 3)
{
; Undocumented COM-interface IPolicyConfig.
IPolicyConfig := ComObject("{870AF99C-171D-4F9E-AF0D-E63Df40c2BC9}", "{F8679F50-850A-41CF-9C72-430F290290C8}")
if (Role & 0x1)
ComCall(13, IPolicyConfig, "Str", DeviceID, "Int", 0) ; Default Device
if (Role & 0x2)
ComCall(13, IPolicyConfig, "Str", DeviceID, "Int", 2) ; Default Communication Device
}
/*
Device Properties (Core Audio APIs)
https://docs.microsoft.com/en-us/windows/win32/coreaudio/device-properties
026E516E-B814-414B-83CD-856D6FEF4822, 2 The friendly name of the audio adapter to which the endpoint device is attached.
A45C254E-DF1C-4EFD-8020-67D146A850E0, 2 The device description of the endpoint device.
A45C254E-DF1C-4EFD-8020-67D146A850E0,14 The friendly name of the endpoint device.
*/
InitDeviceProp(clsid, n)
{
clsid := CLSIDFromString(clsid, Buffer(16+4))
NumPut("Int", n, clsid, 16)
return clsid
}
GetDeviceProp(ptr, clsid, n)
{
; IPropertyStore::GetValue method.
; https://docs.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-ipropertystore-getvalue
ComCall(5, ptr, "Ptr", InitDeviceProp(clsid, n), "Ptr", pvar := PropVariant())
return String(pvar)
}
GetDeviceID(list, name)
{
for device in list
if InStr(device["Name"], name)
return device["ID"]
throw
}
CLSIDFromString(Str, Buffer := 0)
{
if (!Buffer)
Buffer := Buffer(16)
DllCall("Ole32\CLSIDFromString", "Str", Str, "Ptr", Buffer, "HRESULT")
return Buffer
}
class PropVariant
{
__New()
{
this.buffer := Buffer(A_PtrSize == 4 ? 16 : 24)
this.ptr := this.buffer.ptr
this.size := this.buffer.size
}
__Delete()
{
DllCall("Ole32\PropVariantClear", "Ptr", this.ptr, "HRESULT")
}
ToString()
{
return StrGet(NumGet(this.ptr, 8, "UPtr")) ; LPWSTR PROPVARIANT.pwszVal
}
}