-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AI-Hotkeys.ahk
1321 lines (1044 loc) · 40.3 KB
/
AI-Hotkeys.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
;;;;;;;;;;;;;;;;;;
; AI-Hotkeys.ahk ; Version 1.4.0.20241106 - Copyright (C) 2024 Wolfram Ravenwolf
;;;;;;;;;;;;;;;;;;
Version = 1.4.0.20241106 ; ^^^^^^^^^^^^^^
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
#MaxMem 4095
#NoEnv
#SingleInstance Force
#Warn
SendMode Input
global Language := GetLanguage()
; ==============================================================================
; English Variables
; ==============================================================================
; ------------------------------------------------------------------------------
; Default (English) Tasks and Instructions
; ------------------------------------------------------------------------------
; X0 = Title
; X1 = Task
; X2 = Instructions
; X3 = Focus
; Primary Hotkeys
global A0 := "Answer"
global A1 := "Compose an answer to the following text"
global A2 := "Answer in my name. Maintain the language and level of formality. Write only the answer, nothing else, not even a greeting. KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global A3 := "writing"
global B0 := "Calculate/Convert"
global B1 := "Calculate/Convert and explain"
global B2 := ""
global B3 := ""
global C0 := "Check correctness"
global C1 := "Check the correctness and justify your assessment"
global C2 := ""
global C3 := ""
global D0 := "Define"
global D1 := "Define"
global D2 := ""
global D3 := ""
global E0 := "Explain simply"
global E1 := "Explain simply and in an easily understandable way"
global E2 := ""
global E3 := ""
global F0 := "Formulate better"
global F1 := "Formulate the following text better (in its original language)"
global F2 := "Improve grammar, spelling, style, tone and comprehensibility while maintaining the original language and level of formality. Use active and direct, friendly and clear formulations instead of modal verbs in the subjunctive such as ""could"", ""should"" or ""would"". Write only the improved version, nothing else, not even a greeting. KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global F3 := "writing"
global G0 := "Check grammar etc."
global G1 := "Check grammar, spelling, style, tone, and comprehensibility of the following text"
global G2 := "Provide specific suggestions for improvement and explain them to me. Prefer active and direct, friendly and clear formulations instead of modal verbs in the subjunctive such as ""could"", ""should"" or ""would"". KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global G3 := "writing"
global Q0 := "Query Perplexity…"
global Q1 := ""
global Q2 := ""
global Q3 := ""
global R0 := "Research"
global R1 := "Research the following topic"
global R2 := ""
global R3 := ""
global S0 := "Summarize"
global S1 := "Summarize"
global S2 := ""
global S3 := ""
global T0 := "Translate"
global T1 := "Translate the following text to or from English"
global T2 := "Write only the translation of the text enclosed in <text> tags, nothing else, not even a greeting. Maintain the original formatting and structure, except for the <text> tags. TRANSLATE BETWEEN GERMAN AND ENGLISH UNLESS ANOTHER LANGUAGE IS EXPLICITLY REQUESTED."
global T3 := "writing"
global V0 := "Clarify/Simplify"
global V1 := "Clarify and simplify the following text linguistically"
global V2 := "Write only the clarified and simplified version, nothing else, not even a greeting. KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global V3 := "writing"
global W0 := "What is"
global W1 := "What is"
global W2 := ""
global W3 := ""
global X0 := "Reject"
global X1 := "Compose a negative response/rejection to the following text"
global X2 := "Answer in my name. Maintain the language and level of formality. Write only the rejection, nothing else, not even a greeting. KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global X3 := "writing"
global YorZ := "Z"
global Z0 := "Accept"
global Z1 := "Compose an affirmative response/acceptance to the following text"
global Z2 := "Answer in my name. Maintain the language and level of formality. Write only the acceptance, nothing else, not even a greeting. KEEP THE ORIGINAL LANGUAGE OF THE TEXT (E.G. ENGLISH OR GERMAN)!"
global Z3 := "writing"
; Secondary Hotkeys
global H0 := ""
global H1 := ""
global H2 := ""
global H3 := ""
global I0 := ""
global I1 := ""
global I2 := ""
global I3 := ""
global J0 := ""
global J1 := ""
global J2 := ""
global J3 := ""
global K0 := ""
global K1 := ""
global K2 := ""
global K3 := ""
global L0 := ""
global L1 := ""
global L2 := ""
global L3 := ""
global M0 := ""
global M1 := ""
global M2 := ""
global M3 := ""
global N0 := ""
global N1 := ""
global N2 := ""
global N3 := ""
global O0 := ""
global O1 := ""
global O2 := ""
global O3 := ""
global P0 := ""
global P1 := ""
global P2 := ""
global P3 := ""
global U0 := ""
global U1 := ""
global U2 := ""
global U3 := ""
global Y0 := ""
global Y1 := ""
global Y2 := ""
global Y3 := ""
; ------------------------------------------------------------------------------
; Default (English) URLs
; ------------------------------------------------------------------------------
global URL_PERPLEXITY := "https://www.perplexity.ai/"
global URL_DICTIONARY := "https://www.merriam-webster.com/"
global URL_DICTIONARY_SEARCH := "https://www.merriam-webster.com/dictionary/"
global URL_GOOGLE := "https://www.google.com/"
global URL_GOOGLE_SEARCH := "https://www.google.com/search?q="
; FIXME: Disabled DeepL due to OpenResty's inability to handle URL-encoded
; newlines (%0A) in request URLs, which results in 404 Not Found errors.
;global URL_TRANSLATOR := "https://www.deepl.com/"
;;global URL_TRANSLATOR_SEARCH := "https://www.deepl.com/translator#auto/auto/"
;global URL_TRANSLATOR_SEARCH := "https://www.deepl.com/en/translator/q/auto/%s/auto/"
; Falling back to Google Translate until this is fixed.
global URL_TRANSLATOR := "https://translate.google.com/"
;global URL_TRANSLATOR_SEARCH := "https://translate.google.com/#auto/auto/"
global URL_TRANSLATOR_SEARCH := "https://translate.google.com/?sl=auto&tl=auto&text=%s&op=translate"
global URL_WIKIPEDIA := "https://en.wikipedia.org/"
global URL_WIKIPEDIA_SEARCH := "https://en.wikipedia.org/w/index.php?search="
; ------------------------------------------------------------------------------
; English Button Captions
; ------------------------------------------------------------------------------
global CLOSE_BUTTON_CAPTION := "❌ Close (Esc)"
global CLEAR_BUTTON_CAPTION := "❎ Clear (Alt+Del)"
global RESTORE_BUTTON_CAPTION := "🔄 Restore (Alt+Ins)"
global SAVE_BUTTON_CAPTION := "✅ Save (Alt+Enter)"
global SEND_BUTTON_CAPTION := "✔️ Send (Ctrl+Enter)"
; ==============================================================================
; German Variables
; ==============================================================================
if (Language = "de") {
;MsgBox, Default (German) Variables
; ------------------------------------------------------------------------------
; Default (German) Tasks and Instructions
; ------------------------------------------------------------------------------
; X0 = Titel
; X1 = Aufgabe
; X2 = Anweisungen
; X3 = Fokus
; Primary Hotkeys
global A0 := "Verfasse Antwort"
global A1 := "Verfasse eine Antwort auf folgenden Text"
global A2 := "Antworte in meinem Namen. Behalte Sprache und Formalitätsgrad bei. Schreibe nur die Antwort, sonst nichts, auch keine Grußformel. BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global A3 := "writing"
global B0 := "Berechne/Konvertiere"
global B1 := "Berechne/Konvertiere und erkläre"
global B2 := ""
global B3 := ""
global C0 := "Prüfe Richtigkeit"
global C1 := "Prüfe die Richtigkeit und begründe deine Einschätzung"
global C2 := ""
global C3 := ""
global D0 := "Definiere"
global D1 := "Definiere"
global D2 := ""
global D3 := ""
global E0 := "Erkläre einfach"
global E1 := "Erkläre einfach und leicht verständlich"
global E2 := ""
global E3 := ""
global F0 := "Formuliere besser"
global F1 := "Formuliere folgenden Text besser (in seiner Originalsprache)"
global F2 := "Verbessere Grammatik, Rechtschreibung, Stil, Ton und Verständlichkeit unter Beibehaltung der ursprünglichen Sprache und des Formalitätsgrads. Verwende aktive und direkte, freundliche und klare Formulierungen anstelle von Modalverben im Konjunktiv wie ""könnte"", ""müsste"", ""sollte"" oder ""würde"". Schreibe nur die verbesserte Fassung, sonst nichts, auch keine Grußformel. BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global F3 := "writing"
global G0 := "Prüfe Grammatik usw."
global G1 := "Prüfe Grammatik, Rechtschreibung, Stil, Ton und Verständlichkeit des folgenden Textes"
global G2 := "Gib mir konkrete Verbesserungsvorschläge und erläutere sie mir. Bevorzuge aktive und direkte, freundliche und klare Formulierungen anstelle von Modalverben im Konjunktiv wie ""könnte"", ""müsste"", ""sollte"" oder ""würde"". BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global G3 := "writing"
global Q0 := "Perplexity…"
global Q1 := ""
global Q2 := ""
global Q3 := ""
global R0 := "Recherchiere"
global R1 := "Recherchiere zu folgendem Thema"
global R2 := ""
global R3 := ""
global S0 := "Fasse zusammen"
global S1 := "Fasse zusammen"
global S2 := ""
global S3 := ""
global T0 := "Übersetze"
global T1 := "Übersetze den folgenden Text ins Deutsche oder aus dem Deutschen"
global T2 := "Schreibe nur die Übersetzung des mit <text>-Tags umgebenen Texts, sonst nichts, auch keine Grußformel. Behalte die ursprüngliche Formatierung und Struktur bei, mit Ausnahme der <text>-Tags. ÜBERSETZE ZWISCHEN DEUTSCH UND ENGLISCH, ES SEI DENN, EINE ANDERE SPRACHE WIRD AUSDRÜCKLICH GEWÜNSCHT."
global T3 := "writing"
global V0 := "Verdeutliche/Vereinfache"
global V1 := "Verdeutliche und vereinfache folgenden Text sprachlich"
global V2 := "Schreibe nur die verdeutlichte und vereinfachte Fassung, sonst nichts, auch keine Grußformel. BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global V3 := "writing"
global W0 := "Was ist"
global W1 := "Was ist"
global W2 := ""
global W3 := ""
global X0 := "Verfasse Absage"
global X1 := "Verfasse eine verneinende/ablehnende Antwort/Absage auf folgenden Text"
global X2 := "Antworte in meinem Namen. Behalte Sprache und Formalitätsgrad bei. Schreibe nur die Absage, sonst nichts, auch keine Grußformel. BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global X3 := "writing"
global YorZ := "Y"
global Y0 := "Verfasse Zusage"
global Y1 := "Verfasse eine bejahende/zustimmende Antwort/Zusage auf folgenden Text"
global Y2 := "Antworte in meinem Namen. Behalte Sprache und Formalitätsgrad bei. Schreibe nur die Zusage, sonst nichts, auch keine Grußformel. BEHALTE DIE ORIGINALSPRACHE DES TEXTS (Z. B. DEUTSCH ODER ENGLISCH) BEI!"
global Y3 := "writing"
; Secondary Hotkeys
global H0 := ""
global H1 := ""
global H2 := ""
global H3 := ""
global I0 := ""
global I1 := ""
global I2 := ""
global I3 := ""
global J0 := ""
global J1 := ""
global J2 := ""
global J3 := ""
global K0 := ""
global K1 := ""
global K2 := ""
global K3 := ""
global L0 := ""
global L1 := ""
global L2 := ""
global L3 := ""
global M0 := ""
global M1 := ""
global M2 := ""
global M3 := ""
global N0 := ""
global N1 := ""
global N2 := ""
global N3 := ""
global O0 := ""
global O1 := ""
global O2 := ""
global O3 := ""
global P0 := ""
global P1 := ""
global P2 := ""
global P3 := ""
global U0 := ""
global U1 := ""
global U2 := ""
global U3 := ""
global Z0 := ""
global Z1 := ""
global Z2 := ""
global Z3 := ""
; ------------------------------------------------------------------------------
; Default (German) URLs
; ------------------------------------------------------------------------------
global URL_PERPLEXITY := "https://www.perplexity.ai/"
global URL_DICTIONARY := "https://www.duden.de/"
global URL_DICTIONARY_SEARCH := "https://www.duden.de/suchen/dudenonline/"
global URL_GOOGLE := "https://www.google.de/"
global URL_GOOGLE_SEARCH := "https://www.google.de/search?q="
; FIXME: Disabled DeepL due to OpenResty's inability to handle URL-encoded
; newlines (%0A) in request URLs, which results in 404 Not Found errors.
;global URL_TRANSLATOR := "https://www.deepl.com/"
;;global URL_TRANSLATOR_SEARCH := "https://www.deepl.com/translator#auto/auto/"
;global URL_TRANSLATOR_SEARCH := "https://www.deepl.com/de/translator/q/auto/%s/auto/"
; Falling back to Google Translate until this is fixed.
global URL_TRANSLATOR := "https://translate.google.de/"
;global URL_TRANSLATOR_SEARCH := "https://translate.google.de/#auto/auto/"
global URL_TRANSLATOR_SEARCH := "https://translate.google.de/?sl=auto&tl=auto&text=%s&op=translate"
global URL_WIKIPEDIA := "https://de.wikipedia.org/"
global URL_WIKIPEDIA_SEARCH := "https://de.wikipedia.org/w/index.php?search="
; ------------------------------------------------------------------------------
; German Button Captions
; ------------------------------------------------------------------------------
global CLOSE_BUTTON_CAPTION := "❌ Schließen (Esc)"
global CLEAR_BUTTON_CAPTION := "❎ Löschen (Alt+Entf)"
global RESTORE_BUTTON_CAPTION := "🔄 Wiederher. (Alt+Einfg)"
global SAVE_BUTTON_CAPTION := "✅ Speichern (Alt+Enter)"
global SEND_BUTTON_CAPTION := "✔️ Senden (Strg+Enter)"
}
; ==============================================================================
; Additional Variables, Default Settings and Win Hotkeys
; ==============================================================================
; Additional Variables
global PREFIX := ""
global SUFFIX := ""
; Default Settings
global CapsLockHotkeys := true ; AI (Perplexity) Hotkeys + CapsLock Hotkeys
global CapsLockOff := true ; Use CapsLock to disable CapsLock
global Pro := "auto" ; Pro Search: auto = only for non-writing tasks, true = always, false = never
global QueryEditor := "tray" ; Query Editor: tray = keep in tray, true = keep in taskbar, false = off
global StartupHelp := 5 ; Show help on startup: show for X seconds, 1 = keep open permanently, 0 = off
global UseDarkTheme := "auto" ; Theme: auto = system, true = dark, false = light
; Win Hotkeys
global WinHotkey_Perplexity := "Q"
global WinHotkey_Dictionary := "B"
global WinHotkey_Google := "G"
global WinHotkey_Translator := "T"
global WinHotkey_Wikipedia := "W"
; ------------------------------------------------------------------------------
; Load custom variables if an INI file exists in My Documents or in Script Dir
; ------------------------------------------------------------------------------
LoadCustomVariables()
; ------------------------------------------------------------------------------
; Win Hotkeys
; ------------------------------------------------------------------------------
if (WinHotkey_Perplexity) {
Hotkey, #%WinHotkey_Perplexity%, Perplexity_Hotkey ; Default: Win+Q
}
if (WinHotkey_Dictionary) {
Hotkey, #%WinHotkey_Dictionary%, Dictionary_Hotkey ; Default: Win+B
}
if (WinHotkey_Google) {
Hotkey, #%WinHotkey_Google%, Google_Hotkey ; Default: Win+G ⚠️ Remove Game Bar: Get-AppxPackage Microsoft.XboxGamingOverlay | Remove-AppxPackage
}
if (WinHotkey_Translator) {
Hotkey, #%WinHotkey_Translator%, Translator_Hotkey ; Default: Win+T
}
if (WinHotkey_Wikipedia) {
Hotkey, #%WinHotkey_Wikipedia%, Wikipedia_Hotkey ; Default: Win+W
}
; ------------------------------------------------------------------------------
; Create Minimized Query Editor
; ------------------------------------------------------------------------------
if (QueryEditor && QueryEditor != "tray") {
CreateQueryEditorGui()
}
; ------------------------------------------------------------------------------
; Show Startup Help
; ------------------------------------------------------------------------------
ShowStartupHelp()
; ==============================================================================
; Functions
; ==============================================================================
; ------------------------------------------------------------------------------
; Get Language
; ------------------------------------------------------------------------------
GetLanguage() {
SetFormat, Integer, Hex
langID := DllCall("GetSystemDefaultUILanguage", "UInt")
SetFormat, Integer, D
Language := "" ; Default (English)
if (langID = 0x0407 or langID = 0x0c07 or langID = 0x0807) ; German (Germany, Austria, Switzerland)
Language := "de" ; German
;else if (langID = 0x0409 or langID = 0x0809) ; English (United States, United Kingdom)
; Language := "en"
; ...
;MsgBox, Language: %Language%
return Language
}
; ------------------------------------------------------------------------------
; Get INI File
; ------------------------------------------------------------------------------
GetIniFile() {
if (Language) {
iniFileName := "AI-Hotkeys-" . Language . ".ini"
} else {
iniFileName := "AI-Hotkeys.ini"
}
iniPaths := []
iniPaths.Push(A_MyDocuments . "\" . iniFileName)
iniPaths.Push(A_MyDocuments . "\AI-Hotkeys.ini")
iniPaths.Push(A_ScriptDir . "\" . iniFileName)
iniPaths.Push(A_ScriptDir . "\AI-Hotkeys.ini")
Loop, % iniPaths.MaxIndex() {
if (FileExist(iniPaths[A_Index])) {
return iniPaths[A_Index]
}
}
return ""
}
; ------------------------------------------------------------------------------
; Load Custom Variables
; ------------------------------------------------------------------------------
LoadCustomVariables() {
global
local iniFile := GetIniFile()
if (!iniFile) {
return
}
;MsgBox, iniFile: %iniFile%
local key, value, parts
FileRead, fileContent, %iniFile%
Loop, Parse, fileContent, `n, `r
{
; Skip empty lines and comments (lines starting with ; or #)
if (A_LoopField = "" || RegExMatch(A_LoopField, "^\s*[;#]"))
continue
; Skip section headers [section]
if (RegExMatch(A_LoopField, "^\[.*\]$"))
continue
StringSplit, parts, A_LoopField, =, %A_Space%%A_Tab%
if (parts0 == 2)
{
key := parts1
value := StrReplace(RegExReplace(parts2, "^""(.*)""$", "$1"), "\n", "`n")
if (value = "0" || value = "false")
%key% := false
else if (value = "1" || value = "true")
%key% := true
else
%key% := value
}
}
}
; ------------------------------------------------------------------------------
; Use Dark Theme
; ------------------------------------------------------------------------------
UseDarkTheme() {
if (UseDarkTheme != "auto")
return UseDarkTheme
try {
RegRead, AppsUseLightTheme, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, AppsUseLightTheme
return (AppsUseLightTheme == 0)
} catch {
return false ; Default to false if unable to read the registry
}
}
; ------------------------------------------------------------------------------
; Help
; ------------------------------------------------------------------------------
Help()
{
local letter
HelpText := ""
if (QueryEditor) {
; Query Editor Hotkeys
HelpText .= "`nQuery Editor Hotkeys:`n"
HelpText .= "LWin+LAlt = Query Editor`n"
}
if (CapsLockHotkeys) {
; AI (Perplexity) Hotkeys
HelpText .= "`nAI (Perplexity) Hotkeys:`n"
Loop, 26 {
letter := Chr(A_Index + 64) ; Convert to uppercase letter
titleVar := letter . "0"
if (%titleVar% != "") {
HelpText .= "CapsLock+" . letter . " = " . %titleVar% . "`n"
}
}
; CapsLock Hotkeys
HelpText .= "`nCapsLock Hotkeys:`n"
HelpText .= "Ctrl+CapsLock = Toggle CapsLock`n"
HelpText .= "CapsLock+F1 = Help`n"
HelpText .= "CapsLock+F2 = Suspend Hotkeys`n"
HelpText .= "CapsLock+F3 = Pause Script`n"
HelpText .= "CapsLock+F4 = Exit`n"
HelpText .= "CapsLock+F5 = Reload Script`n"
HelpText .= "CapsLock+F12 = Edit Script`n"
}
; Win Hotkeys
if (WinHotkey_Perplexity || WinHotkey_Dictionary || WinHotkey_Google || WinHotkey_Translator || WinHotkey_Wikipedia) {
HelpText .= "`nWin Hotkeys:`n"
if (WinHotkey_Perplexity)
HelpText .= "Win+" . Format("{:U}", WinHotkey_Perplexity) . " = Perplexity`n"
if (WinHotkey_Dictionary)
HelpText .= "Win+" . Format("{:U}", WinHotkey_Dictionary) . " = Dictionary`n"
if (WinHotkey_Google)
HelpText .= "Win+" . Format("{:U}", WinHotkey_Google) . " = Google`n"
if (WinHotkey_Translator)
HelpText .= "Win+" . Format("{:U}", WinHotkey_Translator) . " = Translator`n"
if (WinHotkey_Wikipedia)
HelpText .= "Win+" . Format("{:U}", WinHotkey_Wikipedia) . " = Wikipedia`n"
}
; Settings
;HelpText .= "`nSettings:`n"
;HelpText .= "CapsLockHotkeys = " . (CapsLockHotkeys = 1 ? "true" : CapsLockHotkeys = 0 ? "false" : CapsLockHotkeys) . "`n"
;HelpText .= "CapsLockOff = " . (CapsLockOff = 1 ? "true" : CapsLockOff = 0 ? "false" : CapsLockOff) . "`n"
;HelpText .= "Pro = " . (Pro = 1 ? "true" : Pro = 0 ? "false" : Pro) . "`n"
;HelpText .= "QueryEditor = " . (QueryEditor = 1 ? "true" : QueryEditor = 0 ? "false" : QueryEditor) . "`n"
;HelpText .= "StartupHelp = " . (StartupHelp = 1 ? "true" : StartupHelp = 0 ? "false" : StartupHelp) . "`n"
;HelpText .= "UseDarkTheme = " . (UseDarkTheme = 1 ? "true" : UseDarkTheme = 0 ? "false" : UseDarkTheme) . "`n"
HelpText := Trim(HelpText, "`n")
; Calculate required height based on text content
StringReplace, HelpText, HelpText, `n, `n, UseErrorLevel
lineCount := ErrorLevel + 1 ; Number of lines (+1 because last line might not end with `n)
lineHeight := 17 ; Approximate height per line in pixels
padding := 10 ; Extra padding in pixels
totalHeight := (lineCount * lineHeight) + padding
; Create GUI with custom buttons
Gui, Help:New, +AlwaysOnTop
if UseDarkTheme() { ; Dark theme colors
Gui, Color, 1E1E1E, 333333 ; Set dark background and control colors
Gui, Font, cSilver, Segoe UI ; Set light text color and font
Gui, +LastFound
WinSet, Transparent, 245
; Force dark mode on the entire window
DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", WinExist(), "Int", 19, "Int*", 1, "Int", 4)
DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", WinExist(), "Int", 20, "Int*", 1, "Int", 4)
} else { ; Light theme colors
Gui, Color, FFFFFF, F0F0F0 ; Set light background and control colors
Gui, Font, cBlack, Segoe UI ; Set dark text color and font
Gui, +LastFound
WinSet, Transparent, 245
}
Gui, Font, s11 bold
Gui, Add, Text, , AI-Hotkeys Version %Version%
Gui, Font, s10 norm
Gui, Help:Add, Edit, ReadOnly w250 h%totalHeight% vHelpText -VScroll +VScroll, %HelpText%
Gui, Help:Add, Button, gCopyHelp w120 h30, ➡️ Clipboard
Gui, Help:Add, Button, x+10 gCloseHelp w120 h30 +Default, % CLOSE_BUTTON_CAPTION
Gui, Help:Show,, AI-Hotkeys Help
; Set focus to the Close button to prevent text selection
GuiControl, Focus, Button2
return
CopyHelp:
GuiControlGet, HelpText,, HelpText
Clipboard := HelpText
return
CloseHelp:
HelpGuiClose:
HelpGuiEscape:
Gui, Help:Destroy
return
}
; ------------------------------------------------------------------------------
; Show Startup Help
; ------------------------------------------------------------------------------
ShowStartupHelp() {
global StartupHelp
; Skip if StartupHelp is 0
if (StartupHelp <= 0)
return
; Show help dialog
Help()
; Keep help dialog open permanently if StartupHelp is 1
if (StartupHelp = 1)
return
global startupHelpActive := true
global remainingSeconds := StartupHelp
; Update the close button text every second
SetTimer, UpdateCountdown, 1000
return
UpdateCountdown:
if !startupHelpActive
return
if WinExist("AI-Hotkeys Help") {
MouseGetPos,,, mouseWin
WinGet, activeWin, ID, AI-Hotkeys Help
; Check if window was manually triggered by hotkey
if (A_ThisHotkey = "SC03A & F1") {
SetTimer, UpdateCountdown, Off
ControlSetText, Button2, % CLOSE_BUTTON_CAPTION, AI-Hotkeys Help
startupHelpActive := false
return
}
; Check for mouse interaction
if (mouseWin = activeWin) {
SetTimer, UpdateCountdown, Off
ControlSetText, Button2, % CLOSE_BUTTON_CAPTION, AI-Hotkeys Help
startupHelpActive := false
return
}
if (remainingSeconds > 0) {
ControlSetText, Button2, % RegExReplace(CLOSE_BUTTON_CAPTION, "\(.*\)$") "(" remainingSeconds ")", AI-Hotkeys Help
remainingSeconds--
} else {
WinClose, AI-Hotkeys Help
SetTimer, UpdateCountdown, Off
startupHelpActive := false
}
} else {
SetTimer, UpdateCountdown, Off
startupHelpActive := false
}
return
}
; ------------------------------------------------------------------------------
; Get Selected Or Clipboard Text
; ------------------------------------------------------------------------------
GetSelectedOrClipboardText() {
ClipboardOld := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 0.5
if (ErrorLevel)
Clipboard := ClipboardOld
text := Clipboard
Clipboard := ClipboardOld
ClipboardOld := ""
return text
}
; ------------------------------------------------------------------------------
; URL Encode
; ------------------------------------------------------------------------------
UrlEncode(str) {
old := A_FormatInteger
SetFormat, Integer, Hex
VarSetCapacity(var, StrPut(str, "UTF-8"), 0)
StrPut(str, &var, "UTF-8")
encoded := ""
Loop
{
code := NumGet(var, A_Index - 1, "UChar")
if (!code)
break
if (code >= 0x30 && code <= 0x39 ; 0-9
|| code >= 0x41 && code <= 0x5A ; A-Z
|| code >= 0x61 && code <= 0x7A ; a-z
|| code = 0x2D ; -
|| code = 0x2E ; .
|| code = 0x5F ; _
|| code = 0x7E) ; ~
encoded .= Chr(code)
else
encoded .= "%" . SubStr(code + 0x100, -1)
}
SetFormat, Integer, %old%
return encoded
}
; ------------------------------------------------------------------------------
; Perplexity
; ------------------------------------------------------------------------------
Perplexity()
{
Run, % URL_PERPLEXITY
Sleep, 1000
WinWait, Perplexity
WinActivate
return
}
; ------------------------------------------------------------------------------
; AI (Perplexity)
; ------------------------------------------------------------------------------
AI(hotkey := "", query := "")
{
;MsgBox, Hotkey: %hotkey%
url := URL_PERPLEXITY
task := ""
instructions := ""
focus := ""
if (hotkey != "")
{
task := %hotkey%1
instructions := %hotkey%2
focus := %hotkey%3
}
if (query == "")
query := GetSelectedOrClipboardText()
if (query != "")
{
prompt := ""
if (PREFIX != "")
prompt .= PREFIX
if (task != "")
{
prompt .= task . ":`n`n"
if (instructions != "")
prompt .= "<text>`n"
prompt .= query
if (instructions != "")
prompt .= "`n</text>`n`n" . instructions
}
else
prompt .= query
if (SUFFIX != "")
prompt .= SUFFIX
;MsgBox, prompt: %prompt%
url .= "search?"
if (focus != "")
url .= "focus=" . focus . "&"
if (Pro && !(Pro = "auto" && focus = "writing"))
url .= "pro=true&"
url .= "q=" . UrlEncode(prompt)
}
;MsgBox, url: %url%
if (StrLen(url) > 16384) {
;MsgBox, 48, 414 Request-URI Too Large, % StrLen(url) . " > 16384"
Perplexity()
ClipboardOld := ClipboardAll
Clipboard := prompt
Sleep, 1000
Send, ^v
Sleep, 1000
Clipboard := ClipboardOld
ClipboardOld := ""
Send, .
Sleep, 1000
Send, {Enter}
} else {
Run, % url
}
return
}
; ------------------------------------------------------------------------------
; Search (Wikipedia+URL=Web)
; ------------------------------------------------------------------------------
Search(Engine)
{
baseUrl := "URL_" . Format("{:U}", Engine)
searchUrl := "URL_" . Format("{:U}", Engine) . "_SEARCH"
query := GetSelectedOrClipboardText()
if (query)
{
if (Engine = "Wikipedia" && RegExMatch(query, "i)^(https?://|www\.)"))
Run, % query
else
{
searchTerm := UrlEncode(StrReplace(RTrim(query, "`n"), "`r"))
if (InStr(%searchUrl%, "%s"))
url := StrReplace(%searchUrl%, "%s", searchTerm)
else
url := %searchUrl% . searchTerm
;MsgBox, url: %url%
Run, % url
}
}
else
Run, % %baseUrl%
return
}
; ==============================================================================
; CapsLock Hotkeys
; ==============================================================================
#If (CapsLockHotkeys)
; Disable the default CapsLock behavior
SetCapsLockState, AlwaysOff
; ------------------------------------------------------------------------------
; AI (Perplexity) Hotkeys
; ------------------------------------------------------------------------------
; Dynamically set hotkeys
Loop, 26
{
letter := Chr(A_Index + 64) ; Convert loop index to uppercase letter (A-Z)
titleVar := letter . "0"
if (%titleVar% != "") {
Hotkey, SC03A & %letter%, AIHandler
}
}
; ⚠️ AutoHotkey executes the auto-execute section of the script first.
; This auto-execute section runs until it hits a return, hotkey, or hotstring.
; Move the hotkeys to the very bottom of the script, after any other code.
; Use Ctrl+CapsLock to toggle CapsLock
^SC03A::SetCapsLockState, % GetKeyState("CapsLock", "T") ? "AlwaysOff" : "AlwaysOn"
; CapsLock+F1 = Help
SC03A & F1::Help()
; CapsLock+F2 = Suspend Hotkeys
SC03A & F2::Suspend
; CapsLock+F3 = Pause Script
SC03A & F3::Pause
; CapsLock+F4 = Exit
SC03A & F4::ExitApp
; CapsLock+F5 = Reload This Script
SC03A & F5::Reload
; CapsLock+F12 = Edit This Script
SC03A & F12::Edit
; ⚠️ Place the hotkey handler after the script's auto-execute section, below the
; hotkey definitions!
AIHandler:
AI(Trim(SubStr(A_ThisHotkey, -1))) ; Extract and trim the letter from the hotkey
return
#If