-
Notifications
You must be signed in to change notification settings - Fork 2
/
Showcase.ahk
3584 lines (2950 loc) · 135 KB
/
Showcase.ahk
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; https://github.com/xypha/AHK-v2-scripts/edit/main/Showcase.ahk
; Last updated 2024.11.29
; Visit AutoHotkey (AHK) version 2 (v2) help for information - https://www.autohotkey.com/docs/v2/
; Search for commands/functions used in this script by using Ctrl + F on the AutoHotkey help webpage - https://www.autohotkey.com/docs/v2/lib/
; comments begin with semi-colon ";" at start of line or space or after code in middle of line
; comments can also be enclosed by `/* */`, like this - /* comment text */
; and these two methods can be combined too :)
; /* AHK v2 Showcase - CONTENTS */
; Settings
; Auto-execute
; = Set default state of Lock keys
; = AHK Dark Mode
; = Show/Hide OS files
; = Initialise ClipArr
; = Initialise ClipArr hotstrings
; = Tray Icon
; = Capitalise first letter opt-in Group
; = Close With Esc/Q/W Group
; = Horizontal Scrolling Group
; = Media Keys Restored Group (disabled)
; = Symbols In File Names Group
; = WrapText variables
; = WrapText Disabled Group
; = End auto-execute
; Hotkeys
; = Check & Reload AHK
; = Remap Keys
; + Disable Keys
; + Keyboard keys
; + Media keys (disabled)
; = Customise CapsLock
; = Move Mouse Pointer pixel by pixel
; = Close or Kill an app window
; + WinClose with !RButton
; + WinKill with ^!F4
; + Kill All Instances Of An App with ^!+F4
; = Adjust Window Transparency keys
; = Recycle Bin shortcut
; = Display Off shortcuts
; = Add Control Panel Tools to a Menu
; = Change Text Case
; = Wrap Text In Quotes or Symbols keys
; = Exchange adjacent letters
; = Toggle Window On Top
; = Process Priority
; = Print Screen keys
; #HotIf Apps
; = AHK Main Window
; = Calculator (classic)
; = Firefox
; = KeePass
; = Notepad++
; + Notepad++ main window
; + Edit .ahk
; = Dark Mode - Window Spy
; = Windows File Explorer
; + Explorer main window
; * Unselect
; * UnGroup
; * Invert selection
; * Show folder/file size in ToolTip
; * Delete Empty Folder
; * Extract from folder & delete
; * Horizontal Scrolling
; * Copy full path
; * Copy file names without path
; * Copy file names without extension and path
; + Locate desktop background
; #HotIf Groups
; = Capitalise the first letter of a sentence
; = Close With Esc/Q/W keys
; = Horizontal Scrolling
; = Media Keys Restored (disabled)
; = Symbols In File Names keys
; Hotstrings - Actions
; = ClipArr keys
; = ClipArr testing
; = Date & Time
; + Format Date / Time
; = URL Encode/Decode
; Hotstrings - Text Replacement
; = Find & Replace in Clipboard
; + Find & Replace dot with space (StrReplace)
; + Find & Replace dot with space (RegEx)
; = Trim and change text
; User-defined functions
; = MyNotification
; + MyNotificationGui
; + EndMyNotif
; = AHK Dark Mode Fn
; + ahkDarkMenu
; = Toggle protected operating system (OS) files
; + ToggleOS
; + CheckRegWrite
; + ToggleOSCheck
; + WindowsRefreshOrRun
; + RefreshExplorer
; = Launch explorer or reuse to open path
; + OpenFolder
; + FocusExplorerAddressBar
; = MultiClip ClipArr
; + ClipChanged
; + InsertInClipArr
; + ClipArr ToolTipFn
; + SaveClipArr
; + PasteVStrings
; + PasteCStrings
; = MultiClip ClipMenu
; + ClipMenuFn
; + ClipTrim
; + SendClipFn
; = Paste instead of Send
; + PasteThis
; + Paste_via_clipboard
; + RestoreClip
; = Adjust Window Transparency
; + GetTrans
; + SetTransByWheel
; + SetTransMenuFn
; + SetTransByMenu
; = Change Text Case
; + ChangeCaseMenuFn
; + ConvertLower
; + ConvertSentence
; + ConvertTitle
; + ConvertUpper
; + ConvertInvert
; + CaseConvert
; = Clipboard Fn
; + CallClipWait
; + CallClipboard
; + CallClipboardVar
; = ToolTip function
; + ToolTipFn
; = Wrap Text In Quotes or Symbols
; + WrapTextMenuFn
; + WrapTextMenuSelectionFn
; + WrapTextFn
; = URL Encode/Decode
; + UrlDecode
; + UrlEncode
; = Kill All Instances Of An App
; + GetKillTitles
; + GetKillTitlesFileList
; = Print Screen Fn
; + SnipMenuFn
; + SnipFromMenu
; + PrintScreenFn
; + ScreenshotFileOp
; = Windows File Explorer Fn
; + FocusFileList
; + GetExplorerSize
; + RBinQuery
; + RBinVisible
; + RBinHidden
; + userSID
; + checkDrivesFn
; + RBinDisplay
; + RBinGenerateTxt
; + SizeFn
; + ValidExplorerPath
; + DeleteEmptyFolder
; + CaptureFolderPath
; + GetExplorerPath
; + WallpaperPath_v4
; + nxtBackground
; = Check if file exists and create/append
; + FileCreate_Or_Append
; = Change MsgBox button text
; + MsgBox_Custom
; + MsgBox_ChangeButtonText
; = Calculator view (classic)
; + checkCalcView
; = Windows Registry
; + RegJump
; + ValidRegistryPath
; = Control Panel Tools
; + ControlPanelMenuFn
; + ControlPanelSelect
; + List of commands
; * Test
;------------------------------------------------------------------------------
; Settings
; Start of script code
#Requires AutoHotkey v2.0
#SingleInstance force
#WinActivateForce
KeyHistory 500 ; Max 500
;------------------------------------------------------------------------------
; Auto-execute
; This section should always be at the top of your script
AHKname := "AHK v2 Showcase v2.17"
; Show notification with parameters - text; duration in milliseconds; position on screen: xAxis, yAxis; timeout by - timer (1) or sleep (0)
MyNotificationGui("Loading " AHKname, 10000, 1550, 985, 1) ; 10000ms = 10 seconds, position bottom right corner (x-axis 1550 y-axis 985) on 1920×1080 display resolution; use timer
;--------
; = Set default state of Lock keys
; Turn on/off upon startup (one-time)
SetCapsLockState "Off" ; CapsLock is off - Use SetCapsLockState "AlwaysOff" to force the key to stay off permanently, and uncomment `Persistent`
SetNumLockState "On" ; NumLock is ON
SetScrollLockState "Off" ; ScrollLock is off
;--------
; = AHK Dark Mode
; check windows registry to see if dark mode is enabled
If not RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1) {
; dark mode is enabled
; Global isLightMode := 0 ; store RegRead results in variable for repeated use
ahkDarkMenu() ; enable dark theme for AHK menus
}
; Else Global isLightMode := 1 ; dark mode is NOT enabled
; download .ahk files from the `Lib` folder in this repo
; and save at the same under a `Lib` folder at the location of your .ahk script file
#Include "Lib\Dark Mode - ToolTip.ahk" ; 2024.10.15
#Include "Lib\Dark Mode - MsgBox.ahk" ; 2024.10.15
; Dark Mode - Window Spy ; 2024.10.15
; manually comment out above lines if dark mode is NOT enabled because "#Include cannot be executed conditionally"
; disable dark mode commands "MyNotification.AddText" and "MyNotification.BackColor" in `MyNotificationGui` function
;--------
; = Show/Hide OS files
A_TrayMenu.Delete ; Delete standard menu
A_TrayMenu.Add "&Toggle OS files", ToggleOS ; User-defined function
A_TrayMenu.Add ; Add a separator
A_TrayMenu.AddStandard ; Restore standard menu
ToggleOSCheck() ; Query registry and check/uncheck
;--------
; = Initialise ClipArr
Global LimitClipArr := 25
; Limit the number of slots to 25 to match Win + V clipboard history slots ; customise limit to your needs
; Note: Higher the number, higher the resource usage and slower the performance/response
; WARNING: Removing the variable entirely may cause infinite loop / app hang
Global ClipArrFile := A_MyDocuments "\ClipArrFile.txt"
; ClipArrFile.txt is saved in default path of AHK's built-in variable: A_MyDocuments
; A_MyDocuments is the full path and name of the current user's "My Documents" folder. Usually corresponds to "C:\Users\<UserName>\Documents" (the final backslash is not included in the variable)
; txt file used instead of ini because 'values longer than 65,535 characters are likely to yield inconsistent results' when using IniRead, IniWrite commands
Global delim := "~•~"
; ~ U+007E TILDE
; • U+2022 BULLET : black small circle
; use a unique string because if an array-slot contains this delimiter by accident, saving and loading array from file will cause errors
; Recommendation: 3 or more characters, preferably symbols with one or more Unicode characters that are difficult to type on standard keyboard. For suggestions, look here - https://stackoverflow.com/questions/492090/least-used-delimiter-character-in-normal-text-ascii-128
Global ClipArr := [] ; set Global variable and assign empty array
; Load array from file if file exists - inspired by https://www.autohotkey.com/boards/viewtopic.php?p=341809#p341809
; `Try` command is used to prevent AutoHotkey from throwing error msg in case file is absent or not in correct path
Try ClipArr := StrSplit(FileRead(ClipArrFile, "UTF-8"), delim, , LimitClipArr)
Catch ; or Else load default values on start - 25 slots containing alphanumerical text
ClipArr := ["Slot 1 Shortcut 1",
"Slot 2 Shortcut 2",
"Slot 3 Shortcut 3",
"Slot 4 Shortcut 4",
"Slot 5 Shortcut 5",
"Slot 6 Shortcut 6",
"Slot 7 Shortcut 7",
"Slot 8 Shortcut 8",
"Slot 9 Shortcut 9",
"Slot 10 Shortcut 0",
"Slot 11 Shortcut Q",
"Slot 12 Shortcut w",
"Slot 13 Shortcut e",
"Slot 14 Shortcut r",
"Slot 15 Shortcut t",
"Slot 16 Shortcut Y",
"Slot 17 Shortcut u",
"Slot 18 Shortcut i",
"Slot 19 Shortcut o",
"Slot 20 Shortcut P",
"Slot 21 Shortcut a",
"Slot 22 Shortcut s",
"Slot 23 Shortcut d",
"Slot 24 Shortcut f",
"Slot 25 Shortcut G"]
; run function whenever clipboard is changed such as when Ctrl + x (Cut) or Ctrl + c (Copy) is pressed
; or when clipboard is altered by other apps/programs
OnClipboardChange ClipChanged
; add current clipboard contents to first clipboard slot in ClipArr on start
InsertInClipArr(A_Clipboard, 1) ; onstart = 1
; save `ClipArr` contents to `ClipArrFile.txt` when the script exits
; except when it is killed by something like "End Task" via Taskbar, Task Manager or similar
OnExit SaveClipArr
;--------
; = Initialise ClipArr hotstrings
PasteVStrings(LimitClipArr) ; User-defined function creates serial hotstrings
PasteCStrings(LimitClipArr)
;--------
; = Tray Icon
path_to_TrayIcon := A_ScriptDir "\icons\Tray\2-512.ico"
; Icon source: https://www.iconsdb.com/caribbean-blue-icons/2-icon.html ; CC License, see credits.md
; I like to number scripts 1, 2, 3... and link the scripts to Numpad shortcuts for easy editing -- see section on "Check & Reload AHK" below
Try TraySetIcon path_to_TrayIcon
Catch as err
SetTimer () => MsgBox("TraySetIcon failed!`n" err.Message "`nPath: " path_to_TrayIcon,, 262144), -100 ; 100ms ; new thread ; 262144 = Always-on-top
;--------
; = Capitalise first letter opt-in Group
GroupAdd "CapitaliseFirstLetter_optIn", "ahk_class Notepad++" ; Notepad++ text editor
;--------
; = Close With Esc/Q/W Group
; GroupAdd "CloseWithQW" , "ahk_exe Taskmgr.exe" ; Windows Task Manager ; requires UIAccess
GroupAdd "CloseWithQW" , "Window Spy for AHKv2 ahk_class AutoHotkeyGUI" ; AHK window spy
GroupAdd "CloseWithQW" , "ahk_class CalcFrame" ; classic calculator
GroupAdd "CloseWithQW" , "Properties ahk_class #32770 ahk_exe mpc-hc.exe" ; MediaInfo in mpc
;--------
; = Horizontal Scrolling Group
GroupAdd "HorizontalScroll1" , "ahk_class ApplicationFrameWindow" ; Modern UWP apps like calc and screen snip
GroupAdd "HorizontalScroll1" , "ahk_class MozillaWindowClass" ; Firefox
GroupAdd "HorizontalScroll1" , "ahk_class SALFRAME" ; LibreOffice
;--------
; = Media Keys Restored Group (disabled)
/* ; uncomment to use, if media keys are remapped to navigation keys in "Remap Keys" section
GroupAdd "MediaKeysRestored" , "ahk_class MediaPlayerClassicW" ; MPC-HC
GroupAdd "MediaKeysRestored" , "MPC-HC D3D Fullscreen" ; MPC-HC Full screen
GroupAdd "MediaKeysRestored" , "ahk_class PotPlayer64" ; PotPlayer
; ahk_class RegEdit_RegEdit ; Registry Editor ; by default because AutoHotkey requires UIAccess
; To enable UIAccess for scripts by default,
; Navigate to the `UiAccessCommandKeyValue` in "HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\uiAccess\Command"
; copy it and paste it as (Default) value in "HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Open\Command"
; Source: https://blog.danskingdom.com/Prevent-Admin-apps-from-blocking-AutoHotkey-by-using-UI-Access/
*/
;--------
; = Symbols In File Names Group
GroupAdd "FileNameSymbols" , "ahk_class CabinetWClass" ; Windows file explorer
GroupAdd "FileNameSymbols" , "ahk_class EVERYTHING" ; Everything
GroupAdd "FileNameSymbols" , "Renaming ahk_exe qbittorrent.exe" ; qBittorrent
GroupAdd "FileNameSymbols" , "Save ahk_class #32770" ; Save As / Save File dialogue
GroupAdd "FileNameSymbols" , "Export ahk_class #32770"
GroupAdd "FileNameSymbols" , "Rename ahk_class #32770"
;--------
; = WrapText variables
Global WrapText_Leading1 := "'" , WrapText_Trailing1 := "'" ; single quotation '' - ' U+0027 : APOSTROPHE
Global WrapText_Leading2 := '"' , WrapText_Trailing2 := '"' ; double quotation "" - " U+0022 : QUOTATION MARK
Global WrapText_Leading3 := "(" , WrapText_Trailing3 := ")" ; round brackets ()
Global WrapText_Leading4 := "[" , WrapText_Trailing4 := "]" ; square brackets []
Global WrapText_Leading5 := "{" , WrapText_Trailing5 := "}" ; flower brackets {}
Global WrapText_Leading6 := "``" , WrapText_Trailing6 := "``" ; accent/backtick ``
Global WrapText_Leading7 := "%" , WrapText_Trailing7 := "%" ; percent sign %%
Global WrapText_Leading8 := "‘" , WrapText_Trailing8 := "’" ; ‘’ - ‘ U+2018 LEFT & ’ U+2019 RIGHT SINGLE QUOTATION MARK {single turned comma & comma quotation mark}
Global WrapText_Leading9 := "“" , WrapText_Trailing9 := "”" ; “” - “ U+201C LEFT & ” U+201D RIGHT DOUBLE QUOTATION MARK {double turned comma & comma quotation mark}
;--------
; = WrapText Disabled Group
GroupAdd "WrapText_disabled" , "ahk_exe mpc-hc.exe" ; MPC-HC
GroupAdd "WrapText_disabled" , "ahk_class CalcFrame" ; Calculator (classic)
; Alt + number shortcuts are used to switch between Standard / Scientific / Programmer / Statistics calculators
; GroupAdd "WrapText_disabled" , "ahk_class MSPaintApp" ; MS Paint (classic)
; commented out MSPaintApp from the group to enable wrapping text when inserting/editing text element (ClassNN: RICHEDIT50W1) - see `WrapTextFn` for more info
;--------
; = End auto-execute
SetTimer () => EndMyNotif(), -1000 ; 1s ; new thread ; Reset notification timer to 1s after code in auto-execute section has finished running
Return ; Ends auto-execute
; Below code can be placed anywhere in your script
;------------------------------------------------------------------------------
; Hotkeys
; ^ is Ctrl / Control key
; >^ is RCtrl / right control key
; <^ is LCtrl / left control key
; ! is Alt key
; >! is RAlt / right ALT
; <! is LAlt / left ALT
; <^>! is ALTGr (LControl & RAlt)
; # is Windows / Win key
; + is Shift key
; = Check & Reload AHK
!Numpad1:: { ; Alt + Numpad1 keys pressed together
ListLines
If WinWait(A_ScriptFullPath " - AutoHotkey v" A_AhkVersion,, 3) ; 3s timeout ; wait for ListLines window to open
WinMaximize
}
^!Numpad1:: { ; Ctrl + Alt + Numpad1 keys pressed together
MyNotificationGui("Updating " AHKname,,, 985, 0) ; 500ms ; use Sleep because reload cancels timers
Reload
}
;------------------------------------------------------------------------------
; = Remap Keys
; + Disable Keys
; Disable keys that you don't use or trigger accidentally too often or become annoying
; such keys are hardware specific - desktop vs. laptop, and may vary according to the region
; comment out the ones that don't work for you or don't apply to you
$ScrollLock:: ; disable Scroll Lock ; $ prefix forces keyboard hook
$NumLock:: ; disable Num Lock
+NumpadDot:: ; Numpad delete (Modifier key - Shift)
NumpadDel::
Insert:: ; Insert mode
+Insert:: ; Shift + Insert
#Insert:: ; Win + Insert
+Numpad0:: ; Numpad Insert
NumpadIns:: {
} ; disable keys - do nothing
;--------
; + Keyboard keys
; Use Alt + Insert to toggle the 'Insert mode' and retain the key's function
; Note: ^Insert = Copy(^c) is Windows default behaviour and is not changed by this code
!Insert::Insert ; Source: https://gist.github.com/endolith/823381
LWin & Tab::AltTab ; Left Win key works as left Alt key - disables task view
RAlt::!Space ; Alt + Space brings up a window's title bar menu
^RCtrl::MButton ; press Left & Right Ctrl button to simulate mouse Middle Click
RCtrl & Up:: Send "{PgUp}" ; Page up - use "&" to create 2-key combo shortcut
RCtrl & Down:: Send "{PgDn}" ; Page down - use a variable number of spaces before Send command without affecting the command itself
RControl & Left:: Send "{Home}" ; Home - use alternate key name for RCtrl
>^Right:: Send "{End}" ; End - use >^ instead of Right Ctrl button and skip using "&"
!m::WinMinimize "A" ; Alt+ M = Minimize active window
; PostMessage 0x0112, 0xF020,,, "A" ; alternative, 0x0112 = WM_SYSCOMMAND, 0xF020 = SC_MINIMIZE
/*
;--------
; + Media keys (disabled)
; remap media keys to navigation keys
; uncomment to use and enable "MediaKeysRestored" if required
Media_Play_Pause::PgUp
Media_Stop::PgDn
Media_Prev::Home
Media_Next::End
+Media_Play_Pause::+PgUp
+Media_Stop::+PgDn
+Media_Prev::+Home
+Media_Next::+End
^Media_Play_Pause::^PgUp
^Media_Stop::^PgDn
^Media_Prev::^Home
^Media_Next::^End
^+Media_Play_Pause::^+PgUp
^+Media_Stop::^+PgDn
^+Media_Prev::^+Home
^+Media_Next::^+End
*/
;------------------------------------------------------------------------------
; = Customise CapsLock
; for a more comprehensive CapsLock script, visit - https://github.com/nascentt/CapShift
^CapsLock::^a ; Select all
<#CapsLock::AltTab ; Switch windows with Right Win + CapsLock
;--------
+CapsLock:: {
SetCapsLockState "On"
MyNotificationGui("CapsLock ON", 10000, 845) ; 10000ms = 10s, change to match KeyWait timeout if needed
SetTimer () => CapsWait(), -100 ; 100ms ; new thread
}
CapsWait() {
; runs in new thread and allows for quick toggling of CapsLock-state with +CapsLock / CapsLock / ESC keys in current thread
KeyWait "Esc", "d t10" ; hit ESC key to skip 10s timeout ; increase timeout duration to keep CapsLock ON for longer
SetCapsLockState "Off" ; Disables CapsLock immediately
MyNotification.Destroy() ; and remove notification
}
;--------
CapsLock:: { ; Turn off CapsLock immediately, if on
If GetKeyState("CapsLock", "T") {
SetCapsLockState "Off"
MyNotification.Destroy()
}
}
;------------------------------------------------------------------------------
; = Move Mouse Pointer pixel by pixel
; Modified from http://www.computoredge.com/AutoHotkey/Downloads/MousePrecise.ahk
#Numpad1::MouseMove -1, 1, 0, "R" ; Win + Numpad1 (SC04F) move down left ↓←
#Numpad2::MouseMove 0, 1, 0, "R" ; Win + Numpad2 (SC050) move down ↓
#Numpad3::MouseMove 1, 1, 0, "R" ; Win + Numpad3 (SC051) move down right ↓→
#Numpad4::MouseMove -1, 0, 0, "R" ; Win + Numpad4 (SC04B) move left ←
#Numpad5::MouseMove 960,540 ; Win + Numpad5 (SC04C) move center mouse • (1920×1080 display)
#Numpad6::MouseMove 1, 0, 0, "R" ; Win + Numpad6 (SC04D) move right →
#Numpad7::MouseMove -1, -1, 0, "R" ; Win + Numpad7 (SC047) move up left ↑←
#Numpad8::MouseMove 0, -1, 0, "R" ; Win + Numpad8 (SC048) move up ↑
#Numpad9::MouseMove 1, -1, 0, "R" ; Win + Numpad9 (SC049) move up right ↑→
^#m::MouseMove 960,540 ; Test mouse position
;------------------------------------------------------------------------------
; = Close or Kill an app window
; Modified from https://superuser.com/a/1554366/391770
; other methods to quit app - https://www.xda-developers.com/how-force-quit-applications-windows/
; also, see section "Close With Esc/Q/W keys"
; + WinClose with !RButton
; Alt + right mouse button = attempt to close window
Alt & RButton:: {
MouseGetPos ,, &id
; detect the unique ID number of the window under the mouse cursor
; The window does not have to be active to be detected. Hidden windows cannot be detected
; WinID := WinExist("A") ; alternative - but 'Active' window might not always be the intended target
winClass := WinGetClass("ahk_id " id) ; Retrieves the specified window's class name
If (winClass !== "Shell_TrayWnd" ; exclude windows taskbar
|| winClass !== "TopLevelWindowForOverflowXamlIsland" ; System tray overflow window
|| winClass !== "Windows.UI.Core.CoreWindow" ; Notification Center
;|| winClass !== "insert your app's window class" ; uncomment to add more apps
)
WinClose("ahk_id " id) ; sends a WM_CLOSE message to the target window
; PostMessage 0x0112, 0xF060,,, "ahk_id " id ; alternative - same as pressing Alt+F4 or clicking a window's close button in its title bar
}
;--------
; + WinKill with ^!F4
; Ctrl + Alt + F4 = attempt to kill window, applies to unresponsive ones when WinClose fails
; briefly tries to close the window normally and if that fails, attempts to terminate the window's process
^!F4::WinKill "A"
/* ; alternative
^!F4:: {
MouseGetPos ,, &id
ProcessClose WinGetProcessName("ahk_id " id)
}
*/
;--------
; + Kill All Instances Of An App with ^!+F4
; Ctrl + Alt + Shift + F4 = attempt to Kill All Instances Of An App
^!+F4:: {
titleLimit := 30 ; limit the heigh of resulting message box
Process_Name := WinGetProcessName("A")
Display := "Kill all instances of this app?`n`n" ; `n = new line
. "Name of process:`t" Process_Name "`n" ; `t = tab
. "Path of process:`t" WinGetProcessPath("ahk_exe " Process_Name) "`n`n"
. "No. of visible windows: " WinGetCount("ahk_exe " Process_Name) "`n" ; no of windows ≠ no of processes
. "Titles of visible windows -`n"
. GetKillTitles(WinGetList("ahk_exe " Process_Name), titleLimit) "`n"
DetectHiddenWindows True
HWNDs := WinGetList("ahk_exe " Process_Name)
msgList := GetKillTitles(HWNDs, titleLimit)
Display .= "Total number of windows: " WinGetCount("ahk_exe " Process_Name) " (incl. hidden)`n"
. "Titles of all windows:`n"
DetectHiddenWindows False ; default
If HWNDs.Length <= titleLimit
result := MsgBox(Display . msgList, A_ScriptName " - WARNING", 1 + 48 + 256 + 262144)
; 1 OKCancel (buttons) 48 Icon! (add Exclamation icon) 256 Default2 (make No the default button to prevent accidental process kill) 262144 = Always on top
Else result := MsgBox_Custom(Display . msgList, A_ScriptName " - WARNING", 48 + 512 + 262144, 3, "OK", "Title List", "Cancel")
; 3 = Yes / No / Cancel ; 48 Icon! 512 Default3 262144 = Always-on-top
If result == "OK" or result == "Yes" { ; MsgBox_Custom Button1
While ProcessExist(Process_Name)
ProcessClose Process_Name
; Run A_ComSpec ' /C Taskkill /IM /F "' Process_Name '"' ; alternative - you might see a flash of command prompt/terminal window. Brief explanation of flags -
; /C Carries out the command and then terminates
; /IM imagename
; /F forcefully terminates
; open Run dialogue (Win + R), paste "cmd.exe /?" and press OK, to see default flags
; then paste "Taskkill /?" (without the quotation marks) in cmd window and press enter to see 'Taskkill' specific flags, filters and examples
}
Else If result == "No" { ; MsgBox_Custom Button2 renamed Title List
filePath := A_Temp "\Kill list.txt"
FileCreate_Or_Append(filePath, Display . GetKillTitlesFileList(HWNDs))
Run '"' filePath '"',,"Max"
}
; Else result == "Cancel" ; MsgBox_Custom Button3
; Return
}
;------------------------------------------------------------------------------
; = Adjust Window Transparency keys
; Modified from https://www.autohotkey.com/board/topic/667-transparent-windows/?p=148102
^+WheelUp:: { ; increases Trans value, makes the window more opaque
MouseGetPos ,, &id
; id := WinExist("A") ; alternative - but 'Active' window might not always be the intended target
Trans := GetTrans(id)
If Trans < 255
Trans := Trans + 20 ; add 20, change for slower/faster transition
If Trans >= 255
Trans := "Off"
SetTransByWheel(Trans, id)
}
^+WheelDown:: { ; decreases Trans value, makes the window more transparent
MouseGetPos ,, &id
Trans := GetTrans(id)
If Trans > 20
Trans := Trans - 20 ; subtract 20, change for slower/faster transition
Else If Trans <= 20
Trans := 1 ; never set to zero, causes ERROR
SetTransByWheel(Trans, id)
}
F8::SetTransMenuFn()
;------------------------------------------------------------------------------
; = Recycle Bin shortcut
^Del:: {
If WinActive("Recycle Bin ahk_class CabinetWClass") ; If windows file explorer is active and recycle bin is in the foreground, empty Bin
FileRecycleEmpty
Else If WinExist("Recycle Bin ahk_class CabinetWClass") ; If explorer is showing recycle bin but is in the background, activate it
WinActivate
; use user defined function "OpenFolder" to
; (a) If an explorer is open but not showing recycle bin, change to Bin and
; (b) If an explorer is not open, then open Bin in explorer
Else {
OpenFolder("::{645ff040-5081-101b-9f08-00aa002f954e}") ; comment out if not desired
; alternative to OpenFolder, directly open recycle bin in a new explorer window with below command
; Run "::{645ff040-5081-101b-9f08-00aa002f954e}" ; If explorer is not open, then open Bin in explorer
}
/* display number of files and size of recycle bin */
; obtain drive letters, Breakdown per drive, total no of files, total size of files, list of files
; and display results in MsgBox
RBinDisplay(RBinQuery())
}
;------------------------------------------------------------------------------
; = Display Off shortcuts
; modified from https://www.autohotkey.com/docs/v2/lib/SendMessage.htm#ExMonitorPower
>^NumpadEnter:: ; with Right hand, press Right Ctrl + NumpadEnter keys
<^Esc:: { ; with Left hand, press Left Ctrl + Esc keys
If ThisHotkey == "^NumpadEnter" {
KeyWait "Control" , "T1" ; use KeyWait instead of Sleep for faster execution
KeyWait "NumpadEnter" , "T1"
}
Else {
KeyWait "Esc" , "T1" ; use KeyWait instead of Sleep for faster execution
KeyWait "Control" , "T1"
}
Sleep 100 ; wait a bit after key release to prevent key release from waking up the monitor again
; Sleep 1000 ; simpler alternative to KeyWait commands
SendMessage 0x0112, 0xF170, 2,, "Program Manager"
; 0x0112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
; Use -1 in place of 2 to turn the monitor on.
; Use 1 in place of 2 to activate the monitor's low-power mode.
; further actions -
; Send "{Media_Stop}" ; stop playing all media
; DllCall("LockWorkStation") ; Lock Workstation - source: https://gist.github.com/raveren/bac5196d2063665d2154#file-aio-ahk-L741
}
;--------
; = Add Control Panel Tools to a Menu
#+x::ControlPanelMenuFn() ; Win + Shift + x
;--------
; = Change Text Case
!c::ChangeCaseMenuFn() ; Alt + C
;--------
; = Wrap Text In Quotes or Symbols keys
#HotIf not WinActive("ahk_group WrapText_disabled")
; disables below hotkeys in apps that belonging to this group because they don't use it or have conflicts
!q::WrapTextMenuFn() ; Alt + Q
; WrapText Keys - Alt + Number (from the number row)
!1::WrapTextFn(WrapText_Leading1 , WrapText_Trailing1, 1) ; enclose in single quotation '' - ' U+0027 : APOSTROPHE
!2::WrapTextFn(WrapText_Leading2 , WrapText_Trailing2, 1) ; enclose in double quotation "" - " U+0022 : QUOTATION MARK
!3::WrapTextFn(WrapText_Leading3 , WrapText_Trailing3, 1) ; enclose in round brackets ()
!4::WrapTextFn(WrapText_Leading4 , WrapText_Trailing4, 1) ; enclose in square brackets []
!5::WrapTextFn(WrapText_Leading5 , WrapText_Trailing5, 1) ; enclose in flower brackets {}
!6::WrapTextFn(WrapText_Leading6 , WrapText_Trailing6, 1) ; enclose in accent/backtick ``
!7::WrapTextFn(WrapText_Leading7 , WrapText_Trailing7, 1) ; enclose in percent sign %%
!8::WrapTextFn(WrapText_Leading8 , WrapText_Trailing8, 1) ; enclose in ‘’ - ‘ U+2018 LEFT & ’ U+2019 RIGHT SINGLE QUOTATION MARK {single turned comma & comma quotation mark}
!9::WrapTextFn(WrapText_Leading9 , WrapText_Trailing9, 1) ; enclose in “” - “ U+201C LEFT & ” U+201D RIGHT DOUBLE QUOTATION MARK {double turned comma & comma quotation mark}
!0::WrapTextFn( "" , "" , 1) ; remove above quotes
#HotIf
;------------------------------------------------------------------------------
; = Exchange adjacent letters
; place cursor between 2 letters. The letters reverse positions - `ab|c` becomes `ac|b`.
; Modified from http://www.computoredge.com/AutoHotkey/Downloads/LetterSwap.ahk
$!l:: { ; Alt + L ; Test: AbC
Send "{Left}+{Right 2}"
clipped := CallClipboardVar(2) ; 2s, Exit
Send SubStr(clipped,2) SubStr(clipped,1,1) "{Left}"
}
;------------------------------------------------------------------------------
; = Toggle Window On Top
; Modified from https://www.autohotkey.com/board/topic/94627-button-for-always-on-top/?p=596509
!t:: { ; Alt + t
Title_When_On_Top := "! " ; change title "! " as required
t := WinGetTitle("A")
ExStyle := WinGetExStyle(t)
If (ExStyle & 0x8) { ; 0x8 is WS_EX_TOPMOST
WinSetAlwaysOnTop 0, t ; Turn OFF and remove Title_When_On_Top
WinSetTitle StrReplace(t, Title_When_On_Top), t
}
Else {
WinSetAlwaysOnTop 1, t ; Turn ON and add Title_When_On_Top
WinSetTitle Title_When_On_Top t, t
}
}
;------------------------------------------------------------------------------
; = Process Priority
; Hit `Win + P` to select and change the priority level of a process
; The current priority level of a process can be seen in the Windows Task Manager.
#p:: {
active_pid := WinGetPID("A")
Process_Name := WinGetProcessName("ahk_pid " active_pid)
PPGui := Gui("AlwaysOnTop +Resize -MaximizeBox +MinSize240x230", "! Set Priority")
PPGui.AddText(, "Press ESCAPE to cancel.")
PPGui.AddText(, "Window:`n" WinGetTitle("ahk_pid " active_pid) "`n`nProcess:`n" ProcessGetPath(active_pid))
PPGui.AddText(, "Double-click to set a new priority level.")
LB := PPGui.AddListBox("r5 Choose1", ["Normal","High","Low","BelowNormal","AboveNormal"])
; Realtime omitted because any process not designed to run at Realtime priority might reduce system stability if set to that level ; add Realtime to ListBox if necessary
LB.OnEvent("DoubleClick", SetPriority)
PPGui.AddButton("default", "OK").OnEvent("Click", SetPriority)
PPGui.OnEvent("Escape", (*) => PPGui.Destroy())
PPGui.OnEvent("Close", (*) => PPGui.Destroy())
PPGui.Show
SetPriority(*) {
PPGui.Hide
Try ProcessSetPriority(LB.Text, active_pid)
Catch ; if error
MyNotificationGui("ERROR! Priority could not be changed!`nProcess: " Process_Name "`nPriority : " LB.Text, 5000) ; 5s
Else ; if successful
MyNotificationGui("Success! Priority changed!`nProcess: " Process_Name "`nPriority : " LB.Text, 5000) ; 5s
Finally PPGui.Destroy()
}
}
;------------------------------------------------------------------------------
; = Print Screen keys
; $PrintScreen:: ; keyboard hook $ ; commented out to preserve default function
#PrintScreen:: { ; Win + PrintScreen
PrintScreenFn ; take screenshot, save and rename
}
; #+r:: ; video snip shortcut, uncomment if desired
^PrintScreen:: ; Ctrl + Print Screen (key name = PrtSc, PrtScn or PrntScrn)
#+s:: { ; Win + Shift + s
SnipMenuFn
}
;------------------------------------------------------------------------------
; #HotIf Apps
; Tailor keyboard shortcuts, commands and functions to specific windows, apps or pre-defined groups of both
; = AHK Main Window
#HotIf WinActive(".ahk - AutoHotkey v ahk_class AutoHotkey")
; because this is to enable below commands to apply on main windows of all running scrips irrespective of v1 or v2
; alternative to #HotIf WinActive(A_ScriptHwnd) applies only to the main window of current script
^Tab:: { ; cycle through main window views like browser tabs
winID := WinActive(".ahk - AutoHotkey v ahk_class AutoHotkey")
Text := WinGetText()
If RegExMatch(Text, "^Script lines most recently executed") { ; Found - ListLines
If A_ScriptHwnd == winID
ListVars ; ListVars - Variables and their contents ; ^v
Else Send "^v"
ToolTipFn("2 ListVars - Variables and their contents", 5000, 150, -25) ; 5s ; add # to avoid confusion
}
Else If RegExMatch(Text, "^Local Variables|^Global Variables") { ; Found - ListVars
If A_ScriptHwnd == winID
ListHotkeys ; ListHotkeys - Hotkeys and their methods ; ^h
Else Send "^h"
ToolTipFn("3 ListHotkeys - Hotkeys and their methods", 5000, 150, -25) ; 5s
}
Else If RegExMatch(Text, "^Type\s+Off\?\s+Level\s+Running\s+Name") { ; Found - ListHotkeys
If A_ScriptHwnd == winID
KeyHistory ; KeyHistory - Key history and script info ; ^k
Else Send "^k"
ToolTipFn("4 KeyHistory - Key history and script info", 5000, 150, -25) ; 5s
}
Else If RegExMatch(Text, "^Window: ") { ; Found - KeyHistory
If A_ScriptHwnd == winID
ListLines ; ListLines - Lines most recently executed ; ^L
Else Send "^l"
ToolTipFn("1 ListLines - Lines most recently executed", 5000, 150, -25) ; 5s
}
Else {
ToolTipFn(A_ThisHotkey ":: InStr Text not found!", 2000) ; 2s
Exit
}
}
^+Tab:: { ; cycle through main window views in reverse
winID := WinActive(".ahk - AutoHotkey v ahk_class AutoHotkey")
Text := WinGetText()
If RegExMatch(Text, "^Script lines most recently executed") { ; Found - ListLines
If A_ScriptHwnd == winID
KeyHistory ; KeyHistory - Key history and script info ; ^k
Else Send "^k"
ToolTipFn("4 KeyHistory - Key history and script info", 5000, 150, -25) ; 5s
}
Else If RegExMatch(Text, "^Local Variables|^Global Variables") { ; Found - ListVars
If A_ScriptHwnd == winID
ListLines ; ListLines - Lines most recently executed ; ^L
Else Send "^l"
ToolTipFn("1 ListLines - Lines most recently executed", 5000, 150, -25) ; 5s
}
Else If RegExMatch(Text, "^Type\s+Off\?\s+Level\s+Running\s+Name") { ; Found - ListHotkeys
If A_ScriptHwnd == winID
ListVars ; ListVars - Variables and their contents ; ^v
Else Send "^v"
ToolTipFn("2 ListVars - Variables and their contents", 5000, 150, -25) ; 5s
}
Else If RegExMatch(Text, "^Window: ") { ; Found - KeyHistory
If A_ScriptHwnd == winID
ListHotkeys ; ListHotkeys - Hotkeys and their methods ; ^h
Else Send "^h"
ToolTipFn("3 ListHotkeys - Hotkeys and their methods", 5000, 150, -25) ; 5s
}
Else {
ToolTipFn(A_ThisHotkey ":: InStr Text not found!", 2000) ; 2s
Exit
}
}
#HotIf
;------------------------------------------------------------------------------
; = Calculator (classic)
#HotIf WinActive("ahk_class CalcFrame")
!1:: ; Standard Calculator
!2:: ; Scientific
!3:: ; Programmer
!4:: ; Statistics
{
; focus is on editing history and Alt + 3 is pressed
If ControlGetClassNN(ControlGetFocus("A")) == "Edit1" AND ThisHotkey = "!3"
WrapTextFn(WrapText_Leading3 , WrapText_Trailing3) ; enclose in round brackets ()
Else ; switch calculator type and go to basic view
Send ThisHotkey "^{F4}"
}
; Toggle Date Calculation view
^d:: {
If checkCalcView() = 1
Send "^{F4}" ; Ctrl + F4 = Basic view
Else Send "^e" ; Ctrl + E = Date Calculation view
}
; Toggle Unit conversion view
^u:: {
If checkCalcView() = 2
Send "^{F4}" ; Ctrl + F4 = Basic view
Else Send "^u" ; Ctrl + U = Unit conversion view
}
^w::^F4 ; Go to Basic view
^Tab:: { ; cycle through calculator views like browser tabs
CalcView := checkCalcView()
If CalcView = 0 ; Basic view
Send "^u" ; Ctrl + U = Unit conversion view
Else If CalcView = 1 ; Unit conversion view
Send "^e" ; Ctrl + E = Date Calculation view
Else If CalcView = 2 ; Date Calculation view
MenuSelect , , "View", "Worksheets", "Mortgage"
Else If CalcView = 3 ; Worksheets > Mortgage
MenuSelect , , "View", "Worksheets", "Vehicle lease"
Else If CalcView = 4 ; Worksheets > Vehicle lease
MenuSelect , , "View", "Worksheets", "Fuel economy (mpg)"
Else If CalcView = 5 ; Worksheets > Fuel economy (mpg)
MenuSelect , , "View", "Worksheets", "Fuel economy (L/100 km)"
Else ; Worksheets > Fuel economy (L/100 km)
Send "^{F4}" ; Ctrl + F4 = Basic view
}
^+Tab:: {
CalcView := checkCalcView()
If CalcView = 0 ; Basic view
MenuSelect , , "View", "Worksheets", "Fuel economy (L/100 km)"
Else If CalcView = 1 ; Unit conversion view
Send "^{F4}" ; Ctrl + F4 = Basic view
Else If CalcView = 2 ; Date Calculation view
Send "^u" ; Ctrl + U = Unit conversion view
Else If CalcView = 3 ; Worksheets > Mortgage
Send "^e" ; Ctrl + E = Date Calculation view
Else If CalcView = 4 ; Worksheets > Vehicle lease
MenuSelect , , "View", "Worksheets", "Mortgage"
Else If CalcView = 5 ; Worksheets > Fuel economy (mpg)
MenuSelect , , "View", "Worksheets", "Vehicle lease"
Else ; Worksheets > Fuel economy (L/100 km)
MenuSelect , , "View", "Worksheets", "Fuel economy (mpg)"
}
#HotIf
; = Firefox
#HotIf WinActive("ahk_class MozillaWindowClass") ; main window ; excludes other dialogue boxes like "Save As" originating from ahk_exe firefox.exe
; Ctrl + Shift + F = close Find Bar
^+f::Send "^f{Esc}"
; Alt + H = open Homepage
!h::Send "^w^t"
; Background image loads correctly. Go backwards and Go forwards button history is lost, but not permanently. Use ^+t to restore most recent closed tab and check tab history OR use check recent history in Firefox Library.
; Send "^Labout:home{Enter}" ; alternative - Go backwards and Go forwards button history is preserved, but blank grey background may be seen instead of new tab background image
; Ctrl + Shift + O = open library / bookmark manager
^+o:: {
If WinActive(" — Mozilla Firefox") ; If not new tab, then open new one
Send "^t"
Else Send "^l" ; If new tab, focus address bar
Sleep 250 ; 250ms ; wait for focus - change as per your system performance
PasteThis("chrome://browser/content/places/places.xhtml")
Send "{Enter}"
}
; Run saved bookmarklet via keyword
; Check my bookmarklet repo - https://github.com/xypha/Bookmarklets
^m:: { ; Ctrl + m
If WinActive("Preferences - Invidious")
MarkletFn("invpref") ; keyword to `Set Invidious preferences in two clicks`
Else If WinActive(" IMDb")
MarkletFn("imdblink") ; keyword to `Open IMDb trailer in a new tab`
Else Send ThisHotkey
}
MarkletFn(key) {
; key must match `Keyword` field of saved bookmarklet in Firefox library
; check here for more details - https://github.com/xypha/Bookmarklets#introduction-to-bookmarklets