-
Notifications
You must be signed in to change notification settings - Fork 1
/
#1 Showcase.ahk
1942 lines (1600 loc) · 76.6 KB
/
#1 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
; Visit AutoHotkey (AHK) version 2 (v2) help for information - https://www.autohotkey.com/docs/v2/
; Search for below commands/functions by using control + F to search on the help webpage - https://www.autohotkey.com/docs/v2/lib/
; comments begin with semi-colon ";" at start of line or space+; " ;" in middle of line
; comments can also be show like this - "/*" comment text "*/"
; and these two methods can be combined too :)
; /* AHK v2 #1 Showcase - CONTENTS */
; Settings
; Auto-execute
; = Set default state of Lock keys
; = Show/Hide OS files
; = Customise Tray Icon
; = Capitalise first letter exclusion Group
; = Close With Esc/Q/W Group
; = Horizontal Scrolling Group
; = Media Keys Group (disabled)
; = Symbols In File Names Group
; = End auto-execute
; Hotkeys
; = Check & Reload AHK
; = Remap Keys
; = Customise CapsLock
; = Move Mouse Pointer 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 shortcut
; = 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
; = Firefox
; = Windows File Explorer
; + General - CabinetWClass
; + Invert selection
; + Show folder size in ToolTip
; + Horizontal Scrolling
; + Copy full path
; + Copy file names without path
; + Copy file names without extension and path
; #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
; = Find & Replace in Clipboard
; + Find & Replace dot with space
; + Find & Replace dot with space (RegEx)
; = Trim Clipboard
; = Date & Time
; + Format Date / Time
; = URL Encode/Decode
; User-defined functions
; = MyNotification
; + MyNotificationGui
; + EndMyNotif
; = Toggle protected operating system (OS) files
; + ToggleOS
; + CheckRegWrite
; + ToggleOSCheck
; + WindowsRefreshOrRun
; = Launch function in new thread with SetTimer
; + NewThread
; = Launch explorer or reuse to open path
; + OpenFolder
; = Adjust Window Transparency
; + GetTrans
; + SetTransByWheel
; + SetTransMenuFn
; + SetTransByMenu
; = Change Text Case
; + ChangeCaseMenuFn
; + ConvertLower
; + ConvertSentence
; + ConvertTitle
; + ConvertUpper
; + ConvertInvert
; + CaseConvert
; = Call ClipWait / Clipboard
; + CallClipWait
; + CallClipboard
; + CallClipboardVar
; = ToolTip SetTimer
; + ToolTipFn
; = Wrap Text In Quotes or Symbols
; + WrapTextMenuFn
; + WrapTextFromMenu
; + EncText
; = URL Encode/Decode
; + UrlDecode
; + UrlEncode
; = Kill All Instances Of An App
; + GetKillTitles
; = Print Screen
; + SnipMenuFn
; + SnipFromMenu
; + PrintScreenFn
; + PrintScreenExec
; = Show folder size Fn
; + GetFolderSize
; + FolderSizeFn
; = Control Panel Tools
; + ControlPanelMenuFn
; + ControlPanelSelect
; + List of commands
; ChangeLog
;------------------------------------------------------------------------------
; Settings
; Start of script code
#Requires AutoHotkey v2.0
#SingleInstance force
#WinActivateForce
KeyHistory 500
; Persistent ; uncomment for standalone AHKs to prevent auto-exit
;------------------------------------------------------------------------------
; Auto-execute
; This section should always be at the top of your script
AHKname := "AHK v2 #1 Showcase v2.08"
; 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
; = 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
; = Customise Tray Icon
I_Icon := A_ScriptDir "\icons\1-512.ico"
; Icon source: https://www.iconsdb.com/caribbean-blue-icons/1-icon.html ; CC License
; I like to number scripts 1, 2, 3... and link the scripts to Numpad shortcuts for easy editing -- see section on "Check & Reload AHK"
If FileExist(I_Icon)
TraySetIcon I_Icon
; = Capitalise first letter exclusion Group
GroupAdd "CapitaliseFirstLetter", "ahk_class #32770" ; Save as dialogue
; = 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 Group (disabled)
; uncomment to use, if media keys are remapped to navigation keys in "Remap Keys" section
GroupAdd "MediaKeys" , "ahk_class MediaPlayerClassicW" ; MPC-HC
GroupAdd "MediaKeys" , "MPC-HC D3D Fullscreen" ; MPC-HC Full screen
GroupAdd "MediaKeys" , "ahk_class PotPlayer64" ; PotPlayer
*/
; = Symbols In File Names Group
GroupAdd "FileNameSymbols" , "ahk_class CabinetWClass" ; Windows file explorer
GroupAdd "FileNameSymbols" , "ahk_class EVERYTHING" ; Everything
GroupAdd "FileNameSymbols" , "Save ahk_class #32770" ; Save As / Save File dialogue
GroupAdd "FileNameSymbols" , "Export ahk_class #32770"
GroupAdd "FileNameSymbols" , "Rename ahk_class #32770"
; = End auto-execute
SetTimer EndMyNotif, -1000 ; 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:: { ; Ctrl + 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 coz reload cancels timers
Reload
}
;------------------------------------------------------------------------------
; = Remap 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
; Use Alt + Insert to toggle the 'Insert mode' and retain the key's function
!Insert::Insert ; Source: https://gist.github.com/endolith/823381
; Note: ^Insert = Copy(^c) as Windows default - this behaviour is not changed by the above
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
/* ; remap media keys to navigation keys - disabled
; uncomment to use and enable "Media Keys Group" 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
NewThread(CapsWait) ; 100ms
}
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 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:: {
Process_Name := WinGetProcessName("A")
Display := ( ; continuation
"Kill all instances of this app?`n`n" ; `n = new line
"Name of process:`t" Process_Name ; `t = tab
"`n`Path of process:`t" WinGetProcessPath("ahk_exe " Process_Name)
"`n`nNo. of visible windows: " WinGetCount("ahk_exe " Process_Name) ; no of windows ≠ no of processes
"`nTitles of visible windows:`n " ; 4 spaces to add indent, but this may vary depending on system font setting
GetKillTitles(WinGetList("ahk_exe " Process_Name)))
DetectHiddenWindows True
Display .= ( ; continuation
"`nNo. of all windows: " WinGetCount("ahk_exe " Process_Name) " (incl. hidden)"
"`nTitles of all windows:`n "
GetKillTitles(WinGetList("ahk_exe " Process_Name)))
DetectHiddenWindows False ; default
Result := MsgBox(Display, A_ScriptName " - WARNING", "Icon! YesNo Default2 262144")
; Options: add Exclamation icon; Yes or No buttons; make No the default button to prevent accidental process kill; 262144 = Always on top
If Result = "Yes"
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
}
;------------------------------------------------------------------------------
; = 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
; Else Run "::{645ff040-5081-101b-9f08-00aa002f954e}" ; If explorer is not open, then open Bin in explorer
}
;------------------------------------------------------------------------------
; = Display Off shortcut
; modified from https://www.autohotkey.com/docs/v2/lib/SendMessage.htm#ExMonitorPower
^Esc:: {
KeyWait "Esc" , "T1" ; use KeyWait instead of Sleep for faster execution
KeyWait "Control" , "T1"
Sleep 100 ; wait a bit after key release in case key release would wake up the monitor again
; Sleep 1000 ; alternative to above commands
SendMessage 0x0112, 0xF170, 2,, "Program Manager" ; 0x0112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
}
;--------
; = 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_exe mpc-hc.exe") ; disable below hotkeys in apps that don't use it or have conflicts - Example: Media Player Classic - Home Cinema
!q::WrapTextMenuFn ; Alt + Q
; WrapText Keys - Alt + number row
!1::EncText("`'" , "`'" ) ; enclose in single quotation '' - ' U+0027 : APOSTROPHE
!2::EncText('`"' , '`"' ) ; enclose in double quotation "" - " U+0022 : QUOTATION MARK
!3::EncText("(" , ")" ) ; enclose in round brackets ()
!4::EncText("[" , "]" ) ; enclose in square brackets []
!5::EncText("{" , "}" ) ; enclose in flower brackets {}
!6::EncText("``" , "``" ) ; enclose in accent/backtick ``
!7::EncText("%" , "%" ) ; enclose in percent sign %%
!8::EncText("‘" , "’" ) ; enclose in ‘’ - ‘ U+2018 LEFT & ’ U+2019 RIGHT SINGLE QUOTATION MARK {single turned comma & comma quotation mark}
!9::EncText("“" , "”" ) ; enclose in “” - “ U+201C LEFT & ” U+201D RIGHT DOUBLE QUOTATION MARK {double turned comma & comma quotation mark}
!0::EncText("" , "" ) ; 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
Send "{Left}+{Right 2}"
clipped := CallClipboardVar(2) ; 2s
Send SubStr(clipped,2) SubStr(clipped,1,1) "{Left}"
; Test: AbC
}
;------------------------------------------------------------------------------
; = 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 + Z` 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.
#z:: {
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
}
^PrintScreen:: ; Ctrl + Print Screen (key name = PrtSc, PrtScn or PrntScrn)
; #+r:: ; video snip shortcut, uncomment if desired
#+s:: { ; Win + Shift + s
SnipMenuFn
}
;------------------------------------------------------------------------------
; #HotIf Apps
; Tailor keyboard shortcuts, commands and functions to specific windows, apps or pre-defined groups of both
; = 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}"
; Ctrl + Shift + H = open Homepage
^+h::Send "^labout:home{Enter}" ; go backwards/forwards button history is preserved
; Send "^w^t" ; alternative - go backwards/forwards button history is lost
; 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 500 ; wait for focus - change as per your system performance
Send "{Raw}chrome://browser/content/places/places.xhtml`n" ; `n = {Enter}
}
; Disable Ctrl + Shift + Q = Exit shortcut
^+q::Return
#HotIf
;--------
; = Windows File Explorer
; + General - CabinetWClass
#HotIf WinActive("ahk_class CabinetWClass")
F1::F2 ; disable opening help in MS edge
; Unselect multiple files/folders
; Source: https://superuser.com/questions/78891/is-there-a-keyboard-shortcut-to-unselect-in-windows-explorer
^+a::F5
;--------
; + Invert selection
; For the Windows 11 23H2 Windows File Explorer
^i:: { ; Ctrl + I
MouseMove 750, 150 ; see Note 1
Send "{Click}" ; click on "see more" option
If WinWait("PopupHost ahk_class Microsoft.UI.Content.PopupWindowSiteBridge ahk_exe explorer.exe",, 1) { ; 1s
; Sleep 500 ; alternative to WinWait ; see Note 2
Send "{Up 3}" ; select "Invert selection" option
; Send "{Enter}" ; see Note 3
}
}
; Note 1: location of "see more" option on screen
; MouseMove - move the mouse cursor to x,y coordinates on 'Screen' use Window Spy to determine coordinates for your own screen(s)
; might want to change "CoordMode" if you have problems, visit help page: https://www.autohotkey.com/docs/v2/lib/CoordMode.htm
; Note 2: wait 500ms for window to respond to keys
; wait times (in milliseconds) don't work sometimes, try changing them to see what is sufficient for your PC spec/performance.
; Sometimes it doesn't work at all on the 1st try (ex: when a new explorer instance is first opened after login/restart)
; but works on subsequent attempts. *shrug* no idea why.
; Note 3: uncomment this line after test of previous steps
; or leave it as is if you prefer to do this step manually, especially if you notice inconsistent selection of options.
/* ; Invert selection - alternative
; For ribbon UI enabled File Explorer (in older Win 11 and 7/8/8.1/10 systems) -
; Modified from https://www.autohotkey.com/boards/viewtopic.php?f=76&t=27564
^i::PostMessage 0x111, 28706,, "SHELLDLL_DefView1", "A"
*/
;--------
; + Show folder size in ToolTip
^!s:: {
; check keyboard focus
ClassNN := ControlGetClassNN(ControlGetFocus("A"))
; If keyboard focus = file list
If ClassNN == "DirectUIHWND2"
WhichFolder := CallClipboardVar(2) ; 2s
; If keyboard focus = address bar
Else If ClassNN == "Microsoft.UI.Content.DesktopChildSiteBridge1" {
WhichFolder := CallClipboardVar(2) ; 2s
Send "{F6 2}{Down}{Home}" ; Return focus to file list
}
; If keyboard focus = navigation pane
Else If ClassNN == "SysTreeView321" {
ToolTipFn("Focus is in Navigation Pane!", -2000) ; 2s
Send "{F6}{Home}" ; Return focus to file list
Exit
}
; keyboard focus = unknown.. search or dialogue box or something else?
Else {
ToolTipFn("Unknown focus!`nClassNN: " ClassNN, -2000) ; 2s
Exit
}
; calculate folder size and display
GetFolderSize(WhichFolder)
}
;--------
; + Horizontal Scrolling
; modified from https://www.autohotkey.com/boards/viewtopic.php?p=466527&sid=6dc4a701e678a7b9ee1241ab0043ebd8#p466527
; Method #5
+WheelUp::PostMessage 0x0114, 0,, "ScrollBar1" ; WM_HSCROLL SB_LINELEFT
+WheelDown::PostMessage 0x0114, 1,, "ScrollBar1" ; WM_HSCROLL SB_LINERIGHT
/* ; disabled, uncomment to use - adds Loop to above commands for faster scrolling
+WheelUp:: {
Loop 3
PostMessage 0x0114, 0,, "ScrollBar1"
}
+WheelDown:: {
Loop 3
PostMessage 0x0114, 1,, "ScrollBar1"
}
*/
;--------
; + Copy full path
; Modified from https://www.autohotkey.com/boards/viewtopic.php?p=61084#p61084
^+c:: { ; Ctrl + Shift + C
CallClipboard(2) ; Timeout 2s
A_Clipboard := A_Clipboard ; change to plain text
}
; Example: C:\Program Files\Mozilla Firefox\firefox.exe
;--------
; + Copy file names without path
!n:: { ; Alt + N
A_Clipboard := RegExReplace(CallClipboardVar(2), "\w:\\|.+\\") ; 2s ; remove path
}
; Example: firefox.exe
;--------
; + Copy file names without extension and path
^!n:: { ; Ctrl + Alt + N
files := RegExReplace(CallClipboardVar(2), "\w:\\|.+\\") ; 2s ; remove path
files := RegExReplace(files, "\.[\w]+(`r`n|`n)","`n") ; remove ext, CR
A_Clipboard := RegExReplace(files, "\.[\w]+$") ; remove last ext
}
; Example: firefox
#HotIf
;------------------------------------------------------------------------------
; #HotIf Groups
; = Capitalise the first letter of a sentence
; modified from https://www.autohotkey.com/board/topic/132938-auto-capitalize-first-letter-of-sentence/?p=719739
#HotIf not WinActive("ahk_group CapitaliseFirstLetter") ; exclude 'Save As' dialogue box
; triggers ; add or disable one or more as needed
; ~NumpadEnter:: ; disabled by default because of too many false positives
; ~Enter:: ; disabled - uncomment to use
~NumpadDot::
~.::
~!::
~?:: {
cfc1 := InputHook("L1 V C","{Space}{LShift}{RShift}{CapsLock}", "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z") ; captures 1st character, visible, case sensitive ; .a → .A
cfc1.Start
cfc1.Wait
If cfc1.EndReason = "Match" {
If ThisHotkey = "~!" or ThisHotkey = "~?" ; If ! or ? is the trigger, then add a space b/w trigger and 1st character ; !a → ! A and ?b → ? B
Send "{BS} +" cfc1.Input
Else {
Send "{BS}+" cfc1.Input ; If Dot or NumpadDot is the trigger, don't add space, coz typing the website address is problematic
; SoundBeep 1500, 50 ; play a sound when successful - Frequency(a number between 37 and 32767), Duration in milliseconds
; SoundPlay "C:\Windows\Media\Windows Information Bar.wav" ; alternative to SoundBeep
; SoundPlay A_WinDir "\Media\Windows Balloon.wav" ; alternative to SoundBeep
}
Exit
}
If cfc1.EndKey = "space" { ; prevent cfc2 from firing for numbers or symbols. Example: 0.2ms is not changed to 0.2Ms
cfc2 := InputHook("L1 V C","{Space}{LShift}{RShift}{CapsLock}", "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z") ; captures 2nd character, visible, case sensitive ; . a → . A
cfc2.Start
cfc2.Wait
If cfc2.EndReason = "Match"
Send "{BS}+" cfc2.Input
}
}
#HotIf
; several other AHK v1 auto-capitalisation scripts are good, such as the one linked above
; and one from computoredge - http://www.computoredge.com/AutoHotkey/Downloads/AutoSentenceCap.ahk
; and many others that use different methods to achieve this goal. Try a few and see what works for you.
;------------------------------------------------------------------------------
; = Close With Esc/Q/W keys
#HotIf WinActive("ahk_group CloseWithQW")
Esc::WinClose("A") ; sends a WM_CLOSE message to the target window
^q::!F4 ; sends Alt + F4
; ^w::PostMessage 0x0112, 0xF060,,, "A" ; same as Alt + F4 or clicking a window's close button in its title bar
#HotIf
;------------------------------------------------------------------------------
; = Horizontal Scrolling
; One of these four methods should work in most situations. If not,
; search the internet for other methods and send me a msg if you find one that works for you.
; Method #1 - send window message(WM) directly to move scroll bar(SB) horizontally
; default method
+WheelUp::SendMessage 0x0114, 0, 0, ControlGetFocus("A") ; scroll left - 0x114 is WM_HSCROLL, 0 is SB_LINELEFT
+WheelDown::SendMessage 0x0114, 1, 0, ControlGetFocus("A") ; scroll right - 1 is SB_LINERIGHT ; same as Loop 1
/* ; disabled - uncomment if needed
; add additional 'Loop' command to any method to increase the speed of scrolling. For example, in method 1
+WheelUp:: {
Loop 3 ; increase/decrease the number of loops for faster/slower scrolling
; WARNING - Do not omit number because it causes infinite loop (which is BAD)
SendMessage 0x0114, 0, 0, ControlGetFocus("A")
}
+WheelDown:: {
Loop 3
SendMessage 0x0114, 1, 0, ControlGetFocus("A")
}
*/
;--------
; Method #2 - simulate horizontal mouse wheel action
; test whether method #2 works using Win + Shift + Wheel Up/Down keys (3-key combo),
; then add window title/class to group #1 in auto-execute section
; to enable simpler Shift + Wheel Up/Down (2-key combo) via #HotIf command
; source: https://www.AutoHotkey.com/boards/viewtopic.php?t=76415
#+WheelUp::WheelLeft
#+WheelDown::WheelRight
; Group "HorizontalScroll1" is defined in auto-execute section
#HotIf WinActive("ahk_group HorizontalScroll1") ; group #1
; +WheelUp::WheelLeft ; doesn't work. Explanation: https://www.autohotkey.com/boards/viewtopic.php?p=551456#p551456
+WheelUp::Send "{WheelLeft}"
+WheelDown::Send "{WheelRight}"
#HotIf
/* ; disabled - uncomment if needed
;--------
; Method #3 - turn on scroll lock and send arrow keys to scroll horizontally
#HotIf WinActive("ahk_group HorizontalScroll2") ; group 2 - not yet defined in auto-execute
; ahk_class XLMAIN ; may apply to MS Excel - modified from https://superuser.com/a/825291/391770
+WheelUp::SendKey("{Left}")
+WheelDown::SendKey("{Right}")
SendKey(key) {
SetScrollLockState "On"
Send key
SetScrollLockState "Off"
}
#HotIf
;--------
; Method #4 - send arrow keys directly if other methods don't work
#HotIf WinActive("ahk_group HorizontalScroll3") ; group 3 - not yet defined in auto-execute
+WheelUp::Send "{Left 3}"
+WheelDown::Send "{Right 3}"
#HotIf
;--------
; Method #5 - horizontal scrolling for windows file explorer
see the section under " + Horizontal Scrolling"
Still not working? Try other niche solutions mentioned here - https://superuser.com/questions/13763/horizontal-scrolling-shortcut-in-windows
*/
;------------------------------------------------------------------------------
; = Media Keys Restored (disabled)
; uncomment to use, if media keys are remapped to navigation keys in "Remap Keys" section
/*
#HotIf WinActive("ahk_group MediaKeys")
; restore default actions
Media_Next::Media_Next
Media_Prev::Media_Prev
Media_Stop::Media_Stop
Media_Play_Pause::Media_Play_Pause
#HotIf
*/
;------------------------------------------------------------------------------
; = Symbols In File Names keys
; inspired by the file renaming scheme of "yt-dlg" app - https://oleksis.github.io/youtube-dl-gui/
#HotIf WinActive("ahk_group FileNameSymbols")
; replace \/:*?"<>| with \⧸ : ✲ ?"<>|
; comment out the ones you don't desire, like \ → \
; :?*:\::{U+FF3C} ; \ → \ | replace U+005C REVERSE SOLIDUS : backslash → U+FF3C FULLWIDTH REVERSE SOLIDUS ; disabled
:?*:/::{U+29F8} ; / → ⧸ | replace U+002F SOLIDUS : slash, forward slash, virgule → U+29F8 BIG SOLIDUS
:?*:`:::{U+FF1A} ; : → : | replace U+003A COLON → U+FF1A FULLWIDTH COLON
:?*:*::{U+2732} ; * → ✲ | replace U+002A ASTERISK : star → U+2732 OPEN CENTRE ASTERISK
:?*:?::{U+FF1F} ; ? → ? | replace U+003F QUESTION MARK → U+FF1F FULLWIDTH QUESTION MARK
:?*:"::{U+FF02} ; " → " | replace U+0022 QUOTATION MARK : double quote → U+FF02 FULLWIDTH QUOTATION MARK
:?*:<::{U+FF1C} ; < → < | replace U+003C LESS-THAN SIGN → U+FF1C FULLWIDTH LESS-THAN SIGN
:?*:>::{U+FF1E} ; > → > | replace U+003E GREATER-THAN SIGN → U+FF1E FULLWIDTH GREATER-THAN SIGN
:?*:|::{U+FF5C} ; | → | | replace U+007C VERTICAL LINE : vertical bar, pipe → U+FF5C FULLWIDTH VERTICAL LINE
; Template -
; :*:*::{U+} ; ? → ? | replace ? → ?
#HotIf
;------------------------------------------------------------------------------
; Hotstrings
; = Find & Replace in Clipboard
; + Find & Replace dot with space
:*:.++:: { ; hotstring ".++"
A_Clipboard := StrReplace(A_Clipboard,"."," ") ; replace each dot with space
}
/*
Find text: "ABC..def.GHI"
Replacement text: "ABC def GHI"
*/
; + Find & Replace dot with space (RegEx)
:*:.r++:: { ; hotstring ".r++"
A_Clipboard := RegExReplace(A_Clipboard,"\.+"," ") ; replace one or more dots with single space
}
/*
Find text: "ABC..def.GHI"
Replacement text: "ABC def GHI"
*/
;------------------------------------------------------------------------------
; = Trim Clipboard
; Trim and change multi-line text to single line
; Modified from https://www.autohotkey.com/board/topic/89839-pasting-plain-text-from-the-clipboard/?p=568613
:?*:v--:: { ; hotstring "v--"
cliptext := RegExReplace(A_Clipboard, "\s+", A_Space) ; replace \s with A_Space = " " (single space)
A_Clipboard := RegExReplace(cliptext, "^ +| +$") ; trim leading/trailing spaces
}
/* Regular Expressions (RegEx) -
\s = [\r\n\t\f\v ]
\r = carriage return
\n = line-feed (newline)
\t = tab
\f = form-feed
\v = vertical white space
" "= white space
see Regular Expressions (RegEx) - Quick Reference in AHK help file for more information
Example text - Input:
Line0 "" (blank line)
Line1 " FUBFUBFI " (leading and trailing space)
Line2 "dvvbvvoe df" (2+ consecutive spaces)
Line3 "" (blank line)
Trimmed text - Output:
Line1 "FUBFUBFI dvvbvvoe df"
Explanation: blank lines are deleted, one or more \s are replaced with space, resulting in Line2 being appended to Line1
*/
; Trim but keep non-blank lines
:?*:v++:: { ; hotstring "v++"
cliptext := RegExReplace(A_Clipboard, "m)^ +| +$") ; m) = multi-line, trim leading/trailing spaces
cliptext := RegExReplace(cliptext, "^\s+|\s+$|`r") ; trim \r, leading/trailing \n
A_Clipboard := RegExReplace(cliptext, " +", A_Space) ; trim double spaces
}
/*
Example text - Input:
Line0 "" (blank line)
Line1 " FUBFUBFI " (leading and trailing space)
Line2 "dvvbvvoe df" (2+ consecutive spaces)
Line3 "" (blank line)
Trimmed text - Output:
Line1 "FUBFUBFI"
Line2 "dvvbvvoe df"
Explanation: blank lines are deleted and spaces are trimmed, but non-blank lines are kept
*/
;------------------------------------------------------------------------------
; = Date & Time
; + Format Date / Time
:*x:d++:: Send FormatTime(, "yyyy.MM.dd") ; sends 2021.02.31