-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinkey.ahk
More file actions
2635 lines (2367 loc) · 86.9 KB
/
inkey.ahk
File metadata and controls
2635 lines (2367 loc) · 86.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
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
; 2nd and 3rd segments of version number MUST be single-digit. See versionNum()
; Update both the following lines at the same time:
ver = 2.0.0.9
;@Ahk2Exe-SetVersion 2.0.0.9
;@Ahk2Exe-SetName InKey
;@Ahk2Exe-SetDescription InKey Keyboard Manager
;@Ahk2Exe-SetCopyright Copyright (c) 2018-2015`, InKey Software
;@Ahk2Exe-SetCompanyName InKey Software
;@Ahk2Exe-SetMainIcon InKey.ico
#NoEnv
#SingleInstance force
#Warn All, OutputDebug
#MaxHotkeysPerInterval 300
#HotkeyInterval 1000
; To implement for TINKER
; - SetPhase, IsPhase
; SetMode(), IsMode for more persistent settings. e.g. smart/plain quote, dev/roman digits
; -Implement 〔KeyChar〕 that provides the character that A_Hotkey would have produced. (Useful for default fallback of user-defined special-function key such as Deva-Winscript 〔TOGGLE〕 (which might be something like Alt+Backslash), and for multi-key handlers such as digits.)
; TODO: Warn if any 〔UNKNOWNS〕 remain in text. (need to redo how AHK file is written)
; TODO: implement multi-ruleset. each ruleset begins with >
; TODO: implement preprocess that prepends rulesets/rules to specified keys
; TODO: implement normalize that appends rulesets to specified keys.
; Problem: A 2nd ruleset (such as preproc or normalization) will result in requiring two BKSP to undo it (if it applied). Also it happens in two steps, so in-btween form is briefly displayed than changed. We need to make the net affect of multiple rulesets happen as a single unit.
; TODO: generate handlers at tinker compile time rather than inkeylib.ahki run time
; TODO: enable define to be inside ##if...
; TODO: Make installation of keyboards smooth again, now that we're calling the .exe to do the install.
; (Some flakiness with name showing badly in config list, with no return value from exe, etc.)
; TODO: When opening Config dialog, *RunAs ftype InKeyKeyboardFile="%A_ScriptDir%" "%1"
; TODO: figure out what when RegisterForPreloading() was supposed to be called (~ line 786)
; Main initialization
Outputdebug ___________________________ INKEY.AHK ___________________
K_ProtocolNum := 5 ; When changes are made to the communication protocol between InKey and InKeyLib.ahki, this number should be incremented in both files.
K_TinkerVersion := versionNum(ver)
K_MinTinkerVersion := 1.956 ; Min required version of Tinker language, converted to a float (as versionNum() does)
SetWorkingDir %A_ScriptDir%
onExit DoCleanup
;~ SetTitleMatchMode 3
SetTitleMatchMode 2
DetectHiddenWindows On
;~ selfHwnd := WinExist(A_ScriptFullPath . " ahk_class AutoHotkey")
selfHwnd := WinExist(A_ScriptFullPath . " ahk_class AutoHotkey")
outputdebug selfHwnd = %selfHwnd%
currentconfigurekbd := -1
currentconfigure := 0
ActiveKbd := -1
ActiveKbdFile =
ActiveKbdHwnd =
ActiveHKL := 0
Kbd2RegCt := 0
ActiveAtLastReq := 0
LastKbdActivationTC := 0
ShowKeyboardNameBalloon := 0
oHKLDisplayName := Object()
KBD_File0 := ""
KBD_FileID0 := ""
KBD_HKL0 := GetDefaultHKL() ; also initializes preLoadedHKLs
oKbdByHKL := Object()
oKbdByHKL[KBD_HKL0] := 0
dblTap := 0
currSendingMode := 0
LastRotID := ""
CounterBefore := 0
CounterAfter := 0
thisAppDoesGreedyBackspace := 0
VKbdHwnd := 0
VKbdShowing := 0
UnregisterUnusedKeyboards := 0
SetFormat, IntegerFast, D
outputdebug Default HKL=%KBD_HKL0%
; Determine whether to store settings in AppData or in the working directory (which may prevent writing)
if (FileExist("StoreUserSettingsInAppData.txt")) {
StoreUserSettingsInAppData := 1
BaseSettingsFolder := A_AppData . "\InKeySoftware"
InKeyINI := BaseSettingsFolder "\InKey.ini"
if (not FileExist(InKeyINI)) {
FileCreateDir %BaseSettingsFolder%
FileCopy InKey.ini, %InKeyINI%
}
} else {
StoreUserSettingsInAppData := 0
BaseSettingsFolder := A_ScriptDir
InKeyINI := "InKey.ini"
}
IniRead GUILang, %InKeyINI%, InKey, GUILang, en
AllowUnsafe := 0
if (FileExist("AllowUnsafeKeyboards.txt")) {
MsgBox 308, Unsafe InKey Keyboards Permitted, InKey is currently configured to allow legacy AHK keyboards. This makes you vulnerable to any malicious keyboard that you might install. Once you have replaced your legacy keyboards with Tinker-format keyboards`, you should disallow unsafe keyboards.`n`nWould you like to disallow unsafe keyboards now?, 15
IfMsgBox Yes
FileDelete AllowUnsafeKeyboards.txt
else
AllowUnsafe := 1
}
InKeyCacheDir = %A_Temp%\InkeyCache
FileCreateDir %InKeyCacheDir%
ActivateKbd(0, KBD_HKL0)
;~ HKLDisplayName%KBD_HKL0% := GetLang(1) ; "Default Keyboard"
oHKLDisplayName[KBD_HKL0] := GetLang(1) ; "Default Keyboard"
ShowSplash() ; validate()
hwndLastActive := WinExist("A")
WinGet hwndTray, ID, ahk_class Shell_TrayWnd
;outputdebug hwndtray = %hwndtray%
; KbdToRequest := -1
GetRegisteredKbds()
Outputdebug Kbd# 0 (Default) HKL=%KBD_HKL0%
InkeyLoadedHKLs := ""
setupCallbacks()
; SendU_Init()
hMSVCRT := DllCall("LoadLibrary", "str", "MSVCRT.dll")
initContext()
Menu KbdMenu, UseErrorLevel
; Read main section of INI file
IniRead UnderlyingLayout, %InKeyINI%, InKey, UnderlyingLayout, %A_Space%
if (not UnderlyingLayout)
UnderlyingLayout := "0000" . A_Language
RegRead UnderlyingLayoutFile, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%UnderlyingLayout%, Layout File
if (not UnderlyingLayoutFile)
UnderlyingLayoutFile := "kbdus.dll"
IniRead FollowWindowsInputLanguage, %InKeyINI%, InKey, FollowWindowsInputLanguage, 1
;IniRead AutoGrabContext, %InKeyINI%, InKey, AutoGrabContext, 0
AutoGrabContext = 0
IniRead PortableMode, %InKeyINI%, InKey, PortableMode, 1
IniRead IsBeta, %InKeyINI%, InKey, Beta, 1
IniRead ShowKeyboardNameBalloon, %InKeyINI%, InKey, ShowKeyboardNameBalloon, 0
IniRead UseAltLangWithoutPrompting, %InKeyINI%, InKey, UseAltLangWithoutPrompting, 0
IniRead GUILang, %InKeyINI%, InKey, GUILang, en
IniRead GUILangName, .Langs\%GUILang%.ini, Language, Name, English
; [Un]/Register InKey to run on Windows start-up, if running from a fixed drive.
DriveGet, driveIsFixed, Type, %A_ScriptFullPath%
driveIsFixed := (driveIsFixed = "Fixed")
if (driveIsFixed) {
IniRead StartWithWindows, %InKeyINI%, InKey, StartWithWindows, 0
if (StartWithWindows) {
QuotedPath = "%A_ScriptFullPath%"
RegRead, pls, HKCU, Software\Microsoft\Windows\CurrentVersion\Run, InKey
if (pls <> QuotedPath)
RegWrite REG_SZ, HKCU, Software\Microsoft\Windows\CurrentVersion\Run, InKey, %QuotedPath%
} else
RegDelete HKCU, Software\Microsoft\Windows\CurrentVersion\Run, InKey
}
IniRead LeaveKeyboardsLoaded, %InKeyINI%, InKey, LeaveKeyboardsLoaded, 0
;IniRead PutMenuAtCursor, %InKeyINI%, InKey, PutMenuAtCursor, 0
; if (not PutMenuAtCursor) {
; WinGetPos TrayX, TrayY, ww, hh, ahk_class ToolbarWindow32, Notification Area
; outputdebug tray: %TrayX%, %TrayY%, %ww%, %hh%
; CoordMode Menu, Screen
; }
; Begin setting up menu
menu tray, nostandard
LangString:=GetLang(2)
menu tray, add, %LangString%, ShowAbout ; About InKey...
LangString:=GetLang(3)
menu tray, add, %LangString%, DoConfigureInKey ; Configure InKey...
LangString:=GetLang(4)
menu tray, add, %LangString%, DoHelp ; InKey Help
; menu tray, add, Follow Language Bar, MenuFollow
; if FollowWindowsInputLanguage
; menu, tray, check, Follow Language Bar
LangString:=GetLang(5)
menu tray, add, %LangString%, MenuAutoGrab ; Auto Grab Context
if AutoGrabContext
menu, tray, check, %LangString% ; Auto Grab Context
LangString:=GetLang(6)
menu tray, add, %LangString%, DoExit ; Exit InKey
menu tray, click, 1
menu tray, tip, InKey
OnString:=GetLang(59) ; ON
OffString:=GetLang(60) ; OFF
KBD_File0 := ""
DispGUIs := 0
DispCmds := 0
numKeyboards = 0
KbdInProc = 0
numKbdFiles = 0
KbdFiles =
FolderList =
Loop, *.*, 2
FolderList = %FolderList%%A_LoopFileName%`n
Sort, FolderList
Loop, parse, FolderList, `n
{ if (A_LoopField = "" or (InStr(A_LoopField, ".") and (A_LoopField <> ".nonInkey"))) ; Ignore the blank item at the end of the list, and ignore any folder containing a dot in the name.
continue
CurrFolder := A_LoopField
CurrKbdTinkerFile := ""
CurrKbdCmd := ""
if (FileExist(CurrFolder "\" CurrFolder ".tinker")) {
CurrKbdTinkerFile := CurrFolder "\" CurrFolder ".tinker"
CurrKbdCmd := CurrFolder . ".ahk"
} else if (AllowUnsafe and FileExist(CurrFolder "\" CurrFolder ".ahk")) {
CurrKbdCmd := CurrFolder . ".ahk"
} else if (A_LoopField <> ".nonInkey") {
continue
}
; Loop for each *.kbd.ini file
KbdList =
Loop, %A_LoopField%\*.kbd.ini
KbdList = %KbdList%%A_LoopFileName%`n
Sort, KbdList
Loop, parse, KbdList, `n
{ if (A_LoopField = "") ; Ignore the blank item at the end of the list.
continue
CurrIni = %CurrFolder%\%A_LoopField%
CurrKbdIni := A_LoopField
if (StoreUserSettingsInAppData) {
oriIni := CurrIni
CurrIni := BaseSettingsFolder "\" CurrIni
if (not FileExist(CurrIni)) {
FileCreateDir %BaseSettingsFolder%\%CurrFolder%
FileCopy %oriIni%, %CurrIni%
}
}
;outputdebug processing file: %CurrIni%
IniRead, ii, %CurrIni%, Keyboard, Enabled, 1
if (not ii) ; skip items marked as disabled
continue
numKeyboards++ ; New keyboard to configure
KBD_IniStem%numKeyboards% := SubStr(CurrKbdIni, 1, StrLen(CurrKbdIni) - 8)
if (CurrKbdTinkerFile) {
KBD_File%numKeyboards% := CurrFolder "." KBD_IniStem%numKeyboards% ".ahk"
KBD_CacheStem%numKeyboards% := InkeyCacheDir "\" CurrFolder "." KBD_IniStem%numKeyboards%
KBD_AhkFile%numKeyboards% := KBD_CacheStem%numKeyboards% ".ahk"
} else {
KBD_File%numKeyboards% := CurrKbdCmd
KBD_AhkFile%numKeyboards% := CurrFolder "\" CurrKbdCmd
}
KBD_Folder%numKeyboards% := CurrFolder
KBD_IniFile%numKeyboards% := CurrIni
KBD_Disabled%numKeyboards% := 0
KBD_IconNum%numKeyboards% := 0
KBD_FileHwnd%numKeyboards% := 0
; KBD_LayoutName%numKeyboards% := SubStr(A_LoopField, 1, InStr(A_LoopField, ".kbd.ini") - 1)
KBD_TinkerFile%numKeyboards% := CurrKbdTinkerFile
IniRead, KBD_LayoutName%numKeyboards%, %CurrIni%, Keyboard, LayoutName, %A_Space%
IniRead, KBD_MenuText%numKeyboards%, %CurrIni%, Keyboard, MenuText, %A_Space%
IniRead, KBD_Hotkey%numKeyboards%, %CurrIni%, Keyboard, Hotkey, %A_Space%
IniRead, KBD_Lang%numKeyboards%, %CurrIni%, Keyboard, Lang, %A_Space%
IniRead, KBD_AltLang%numKeyboards%, %CurrIni%, Keyboard, AltLang, %A_Space%
IniRead, KBD_Icon%numKeyboards%, %CurrIni%, Keyboard, Icon, %A_Space%
IniRead, KBD_Params%numKeyboards%, %CurrIni%, Keyboard, Params, %A_Space%
IniRead, KBD_DisplayCmd%numKeyboards%, %CurrIni%, Keyboard, LayoutHelp, %A_Space%
; outputdebug % CurrIni ">> z. layouthelp = " KBD_DisplayCmd%numKeyboards%
if (KBD_DisplayCmd%numKeyboards% = "")
IniRead, KBD_DisplayCmd%numKeyboards%, %CurrIni%, Keyboard, DisplayCmd, %A_Space% ; Old name for LayoutHelp
; outputdebug % "a. layouthelp = " KBD_DisplayCmd%numKeyboards%
if ((RegExMatch(KBD_DisplayCmd%numKeyboards%, "i)\.(pdf|png|doc|docx|txt|htm|html|jpg)$")
or (RegExMatch(KBD_DisplayCmd%numKeyboards%, "i)\.ahk$") and AllowUnsafe))
and FileExist(KBD_Folder%numKeyboards% . "\" . KBD_DisplayCmd%numKeyboards% )) {
if (RegExMatch(KBD_DisplayCmd%numKeyboards%, "i)\.tinker\.html$"))
{ ; LayoutHelp file is one we generate
KBD_DisplayCmdSrc%numKeyboards% := KBD_Folder%numKeyboards% . "\" . KBD_DisplayCmd%numKeyboards% ; If the keyboard help file exists in the keyboard's folder, prepend path.
KBD_DisplayCmd%numKeyboards% := KBD_CacheStem%numKeyboards% ".html"
} else {
KBD_DisplayCmdSrc%numKeyboards% =
KBD_DisplayCmd%numKeyboards% := KBD_Folder%numKeyboards% . "\" . KBD_DisplayCmd%numKeyboards% ; If the keyboard help file exists in the keyboard's folder, prepend path.
}
} else {
KBD_DisplayCmd%numKeyboards% =
KBD_DisplayCmdSrc%numKeyboards% =
}
; outputdebug % "b. layouthelp = " KBD_DisplayCmd%numKeyboards%
if (AllowUnsafe) {
IniRead, KBD_ConfigureGUI%numKeyboards%, %CurrIni%, Keyboard, ConfigureGUI, %A_Space%
} else {
KBD_ConfigureGUI%numKeyboards% =
}
IniRead, KbdKLID%numKeyboards%, %CurrIni%, Keyboard, KLID, %A_Space%
KBD_HKL%numKeyboards% = ""
ProcessKbd()
}
}
; now deal with the keyboards that needed registration or unregistration
if (PortableMode or not UnregisterUnusedKeyboards)
UnusedRKCt := 0
if (UnusedRKCt or Kbd2RegCt) { ; This will only be true when running in Installed mode. (PortableMode=0)
if (A_IsAdmin) { ; We have the necessary permissions to do this now.
if (UnusedRKCt) {
; Unregister any old keyboards not used
UnloadCt := 0
Loop % RKCt {
if (not RK_Used%A_Index%) {
key := RK_KLID%A_Index%
RegDelete HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%key%
outputdebug RegDelete HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%key%
; If keyboard had previously been configured for pre-loading, undo that.
id := RK_LID%A_Index%
hkl := "0xF" . substr(RK_LID%A_Index%, -2) . substr(RK_KLID%A_Index%, -3)
UnloadCt += DllCall("UnloadKeyboardLayout","uint",hkl)
}
}
if (UnloadCt)
RefreshLangBar() ; Doing this here will cause Windows to take care of deleting registry residue from HKCU... Preload and Substitutes
}
; TODO: Calculate MaxLID here (after the above deletions) instead, otherwise, repeated changes will use up LIDs. Actually, some day we ought to be smart enough to use the lower LIDs that were unused.
if (Kbd2RegCt) {
; Register and load any keyboards needing it
Loop % Kbd2RegCt
{ ; Do registration
kk := Kbd2Reg%A_Index%
KBD_HKL%kk% := RegisterAndLoadKeyboard(kk)
oKbdByHKL[KBD_HKL%kk%] := kk
SetFormat, IntegerFast, d
}
}
} else { ; not A_IsAdmin
; There are keyboards needing registered or unregistered, but user does not have Admin privileges.
Gui Hide
TitleString:=GetLang(116) ; Install/update Keyboard registration?
TempString:= UnregisterUnusedKeyboards ? (GetLang(117) . " " . UnusedRKCt . "`n") : ""
TempString .= GetLang(118) . " " . Kbd2RegCt . "`n`n" . GetLang(119) . "`n" . GetLang(120) . "`n" . GetLang(121) . "`n`n" . GetLang(122)
MsgBox 36, %TitleString%, %TempString% ; # Keyboards to unregister: %UnusedRKCt%`n# Keyboards to register: %Kbd2RegCt%`n`nFor InKey to run in its "Installed" mode, it must first update the keyboard registry to match your settings.`nDoing so requires full administrator permissions.`nIf you do not have administrator permissions on this computer, InKey can still run in "Portable" mode.`n`nWould you like to restart InKey with full administrator permissions?
ifMsgBox Yes
{ DllCall("shell32\ShellExecuteW", uint, 0, str, "RunAs", str, A_ScriptFullPath, str, "ReloadAsAdmin", str, A_ScriptDir, int, 1)
sleep 2000
exitapp
}
PortableMode = 1
Gui Show
Loop % Kbd2RegCt
{ ; Use substitute keyboards instead
kk := Kbd2Reg%A_Index%
KBD_HKL%kk% := LoadSubstituteKeyboard(KBD_Lang%kk%, KBD_LayoutName%kk%)
oKbdByHKL[KBD_HKL%kk%] := kk
}
}
}
KbdInProc =
FolderList =
found =
KbdFiles =
; DRM: The following section was cut because it seemed to interfere with inkey-specified layout names. it seems to still work for non-inkey layouts.
;~ Loop, Parse, preloadedHKLs, %A_Space%
;~ {
;~ if ((A_LoopField <> "") and (HKLDisplayName%A_LoopField% = "")) ; Ignore the blank item at the end of the list, and any HKL for which we already have a display name
;~ if ((A_LoopField <> "") and (oHKLDisplayName.HasKey(A_LoopField))) ; Ignore the blank item at the end of the list, and any HKL for which we already have a display name
;~ {
;; HKLDisplayName%A_LoopField% := GetHKLDisplayName(A_LoopField)
;~ oHKLDisplayName[A_LoopField] := GetHKLDisplayName(A_LoopField)
;~ OutputDebug % "We just looked up displayname for " A_LoopField "=>" oHKLDisplayName[A_LoopField]
;~ }
;~ }
IniRead RefreshLangBarOnLoad, %InKeyINI%, InKey, RefreshLangBarOnLoad, 2
if (InkeyLoadedHKLs) {
if (RefreshLangBarOnLoad = 1)
RefreshLangBar() ; Slow but sure
else if (RefreshLangBarOnLoad = 2) { ; Post WM_INPUTLANGCHANGEREQUEST to HWND_BROADCAST
DllCall("PostMessage", "UInt", 0xffff, UInt, 0x50, UInt, 1, UInt, LastLoadedHKL) ; First change it to something else
DllCall("PostMessage", "UInt", 0xffff, UInt, 0x50, UInt, 1, UInt, KBD_HKL0) ; Then change it back to default lang.
}
}
if numKeyboards <> 0
{
menu tray, add
LangString:=GetLang(7)
menu tray, add, %LangString%, :DispConfigureSubmenu ; Configure keyboard options
if (DispCmds) {
LangString:=GetLang(8)
menu tray, add, %LangString%, :DispCmdSubmenu ; Display keyboard layout
}
menu tray, add
LangString:=GetLang(9)
menu tray, add, %LangString%, ShowKbdMenu ; Select Keyboard
menu tray, default, %LangString% ; Show it in boldface
;IniRead KBD_MenuText0, %InKeyINI%, InKey, DefaultKbdMenuText, & Default keyboard
menu KbdMenu, add
KBD_MenuText0:=GetLang(10)
menu KbdMenu, add, %KBD_MenuText0%, KeyboardMenuItem ; Add menu item for default keyboard
menu KbdMenu, check, %KBD_MenuText0%
}
; ============Set up hotkeys.
IniRead ii, %InKeyINI%, InKey, ResyncHotkey, %A_Space%
; Resync Keyboards with InKey - Workaround for a bug
if (ii)
Hotkey %ii%, DoResync, UseErrorLevel
; Reload InKey
IniRead ii, %InKeyINI%, InKey, ReloadHotkey, %A_Space%
if (ii)
Hotkey %ii%, DoReload, UseErrorLevel
; DefaultKbdHotkey
IniRead KBD_Hotkey0, %InKeyINI%, InKey, DefaultKbdHotkey, %A_Space%
if (KBD_Hotkey0)
Hotkey %KBD_Hotkey0%, OnKbdHotkey, UseErrorLevel
; DefaultKbdDoubleTap
IniRead ii, %InKeyINI%, InKey, DefaultKbdDoubleTap, %A_Space%
if (ii) {
HotKey %ii% & ~s, Nothing, UseErrorLevel ; Make key a prefix by using it in front of "&" at least once. Use tilde so normal behavior occurs.
HotKey %ii%, DblTapDefKbd, UseErrorLevel
}
; ToggleKbdHotkey
IniRead ii, %InKeyINI%, InKey, ToggleKbdHotkey, %A_Space%
if (ii)
Hotkey %ii%, HotkeyToggleKbd, UseErrorLevel
; ToggleKbdDoubleTap
IniRead ii, %InKeyINI%, InKey, ToggleKbdDoubleTap, %A_Space%
if (ii) {
HotKey %ii% & ~s, Nothing, UseErrorLevel ; Make key a prefix by using it in front of "&" at least once. Use tilde so normal behavior occurs.
HotKey %ii%, DblTapToggleKbd, UseErrorLevel
}
; NextKbdHotkey
IniRead ii, %InKeyINI%, InKey, NextKbdHotkey, %A_Space%
if (ii)
Hotkey %ii%, RequestNextKbd, UseErrorLevel
; NextKbdDoubleTap
IniRead ii, %InKeyINI%, InKey, NextKbdDoubleTap, %A_Space%
if (ii) {
HotKey %ii% & ~s, Nothing, UseErrorLevel ; Make key a prefix by using it in front of "&" at least once. Use tilde so normal behavior occurs.
HotKey %ii%, DblTapNextKbd, UseErrorLevel
}
; PrevKbdHotkey
IniRead ii, %InKeyINI%, InKey, PrevKbdHotkey, %A_Space%
if (ii)
Hotkey %ii%, RequestPrevKbd, UseErrorLevel
; PrevKbdDoubleTap
IniRead ii, %InKeyINI%, InKey, PrevKbdDoubleTap, %A_Space%
if (ii) {
HotKey %ii% & ~s, Nothing, UseErrorLevel ; Make key a prefix by using it in front of "&" at least once. Use tilde so normal behavior occurs.
HotKey %ii%, DblTapPrevKbd, UseErrorLevel
}
; MenuHotkey
IniRead ii, %InKeyINI%, InKey, MenuHotkey, %A_Space%
if (ii)
Hotkey %ii%, ShowKbdMenu, UseErrorLevel
; MenuDoubleTap
IniRead ii, %InKeyINI%, InKey, MenuDoubleTap, %A_Space%
if (ii) {
; HotKey ~%ii% & SC200, Nothing, UseErrorLevel
HotKey %ii% & ~s, Nothing, UseErrorLevel ; Make key a prefix by using it in front of "&" at least once. Use tilde so normal behavior occurs.
HotKey %ii%, DblTapMenuKbd, UseErrorLevel
}
; AutoGrabContextHotkey
IniRead ii, %InKeyINI%, InKey, AutoGrabContextHotkey, %A_Space%
if (ii)
Hotkey %ii%, MenuAutoGrab, UseErrorLevel
; GrabContextHotkey
IniRead ii, %InKeyINI%, InKey, GrabContextHotkey, %A_Space%
if (ii)
Hotkey %ii%, GrabContext, UseErrorLevel
; ChangeSendingMode hotkey
IniRead ii, %InKeyINI%, InKey, ChangeSendingMode, %A_Space%
if (ii)
Hotkey %ii%, ChangeSendingMode, UseErrorLevel
; ClearContextHotkey
; IniRead ii, %InKeyINI%, InKey, ClearContextHotkey, %A_Space%
; if (ii)
; Hotkey $%ii%, CLEARCONTEXT, UseErrorLevel
; All keyboard hotkeys (previously read)
Loop % numKeyboards
{ hk := GetKbdHotkey(A_Index)
if (hk)
Hotkey %hk%, OnKbdHotkey, UseErrorLevel
}
CoordMode, ToolTip
if (RefreshLangBarOnLoad = 2 and InkeyLoadedHKLs)
{ ; Post WM_INPUTLANGCHANGEREQUEST to HWND_BROADCAST
; DllCall("PostMessage", "UInt", 0xffff, UInt, 0x50, UInt, 1, UInt, LastLoadedHKL) ; First change it to something else
DllCall("PostMessage", "UInt", 0xffff, UInt, 0x50, UInt, 1, UInt, KBD_HKL0) ; Then change it back to default lang.
ChangeLanguage(KBD_HKL0)
}
IniRead PreviewAtCursor, %InKeyINI%, InKey, PreviewAtCursor, 1
IniRead rotaPeriod, %InKeyINI%, InKey, SpeedRotaPeriod, 1000
; ChangeLanguage(KBD_HKL0) ; Just to be sure
; OnMessage(0x6, "On_WM_ACTIVATE")
tipHwnd := CreateUTip()
; tipTxt
Loop % numKeyboards {
kk := A_Index
OutputDebug % kk . " " . KBD_LayoutName%kk% . " " . KBD_FileID%kk% . " " . KBD_File%kk% . " " . KBD_HKL%kk%
}
; Process Tinker files
Loop % numKeyboards {
kk := A_Index
if (KBD_TinkerFile%kk%) {
if ((not FileExist(KBD_AhkFile%kk%)) or FileIsOlderThan(KBD_AhkFile%kk%, KBD_TinkerFile%kk%) or FileIsOlderThan(KBD_AhkFile%kk%, A_ScriptFullPath) or FileIsOlderThan(KBD_AhkFile%kk%, KBD_IniFile%kk%) or (KBD_DisplayCmdSrc%kk% and FileIsOlderThan(KBD_DisplayCmd%kk%, KBD_DisplayCmdSrc%kk%))) {
GUIControl,, splashTxt, % "Recompiling keyboard:" chr(10) KBD_LayoutName%kk%
err := ProcessTinkerFile(kk)
GUIControl,, splashTxt, %A_Space%
if (err) {
Gui Hide
MsgBox %err%
}
if (tinkWarnings) {
Gui hide
MsgBox 260, Warning, % "Warnings were encountered while processing " KBD_Folder%kk% ".tinker`nView warnings now?"
IfMsgBox Yes
Run % "notepad """ KBD_AhkFile%kk% """"
}
}
}
}
gui hide
SetTimer CHECKLOCALE, 500
if (numKeyboards = 0) {
Gui Hide
goto WelcomeToInKey
}
return
FileIsOlderThan(this, that) {
FileGetTime thisTime, %this%
FileGetTime thatTime, %that%
EnvSub thisTime, %thatTime%, S
; outputdebug FileIsOlderThan(%this%, %that%) => %thisTime%
return (thisTime < 0)
}
ProcessKbd() {
global
static ProcdKbdList := ""
local kk := numKeyboards
ProcessKbdErrors:
if (KBD_Disabled%kk%) {
;or ( KBD_File%kk% and not FileExist(KBD_Folder%kk% . "\" . KBD_File%kk%))) {
; local xx := KBD_MenuText%kk%
; outputdebug ignoring %fldr% %xx%
IniWrite 0, % KBD_IniFile%kk%, Keyboard, Enabled
KBD_FileID%kk% =
KBD_File%kk% =
KBD_AhkFile%kk% =
KBD_MenuText%kk% =
KbdHotkeyCode%kk% =
KBD_LayoutName%kk% =
KBD_Lang%kk% =
KBD_Icon%kk% =
KBD_Params%kk% =
KbdKLID%kk% =
KBD_Disabled%kk% =
KBD_ConfigureGUI%kk% =
KBD_RunGUI%kk% =
KBD_DisplayCmd%kk% =
KBD_RunCmd%kk% =
KBD_AltLang%kk% =
KBD_HKL%kk% =
KBD_OptionsFile%kk% =
numKeyboards--
return
}
; populate submenu for all enabled keyboards
Menu, DispConfigureSubmenu, add, % KBD_MenuText%kk%, DispConfigureMenuItem
; populate submenu if keyboard has a layout help file
if (KBD_DisplayCmd%kk%) {
DispCmds++
ii := KBD_MenuText%kk%
Menu, DispCmdSubmenu, add, %ii%, DispCmdMenuItem
}
if (KBD_LayoutName%kk%) {
; These are the settings for an InKey keyboard
local ln := KBD_LayoutName%kk%
; Check that the language code is valid on this machine
if (not KBD_Lang%kk%) {
Gui Hide
TitleString:=GetLang(123) ; Configuration Error
TempString:=GetLang(124) ; The language code for keyboard "%ln%" is missing.
MsgBox 0, %TitleString%, %TempString%
Gui Show
KBD_Disabled%kk% := 1
goto ProcessKbdErrors
}
if (strlen(KBD_Lang%kk%) <> 4) {
Gui Hide
TitleString:=GetLang(123) ; Configuration Error
TempString:=GetLang(125) ; The language code for keyboard "%ln%" should be a 4-hexidecimal-digit code representing the language ID.
MsgBox 0, %TitleString%, %TempString%
Gui Show
KBD_Disabled%kk% := 1
goto ProcessKbdErrors
}
local priLang := "0x" . KBD_Lang%kk%
local sLangName
VarSetCapacity( sLangName, 260, 0 )
DllCall("GetLocaleInfo","uint",priLang & 0xFFFF,"uint", 0x1001, "str",sLangName, "uint",260) ; LOCALE_SENGLANGUAGE=0x1001
if (strlen(sLangName) < 1) {
if (KBD_AltLang%kk%) {
local altLang := "0x" . KBD_AltLang%kk%
DllCall("GetLocaleInfo","uint", altLang & 0xFFFF,"uint", 0x1001, "str",sLangName, "uint",260) ; LOCALE_SENGLANGUAGE=0x1001
if (sLangName) {
if (UseAltLangWithoutPrompting) {
KBD_Lang%kk% := KBD_AltLang%kk%
goto LangCodeOK
} else {
Gui Hide
TitleString:=GetLang(126) ; Use %sLangName% language for '%ln%' layout?
LangCode:= KBD_Lang%kk%
TempString:= GetLang(127) . " " . LangCode . " " . GetLang(128) . "`n`n" . GetLang(129) . "`n`n" . GetLang(130) . " " . sLangName . " " . GetLang(131) . " " . ln . " " . GetLang(132) ; "The language code " . %LangCode% . " is unknown on this version or service-pack of Windows.`n`nSome applications may not function properly with an unknown language.`n`nWould you like to instead use " . sLangName . " for the '" . ln "' keyboard?"
MsgBox 4, %TitleString%, %TempString%
Gui Show
ifmsgbox Yes
KBD_Lang%kk% := KBD_AltLang%kk%
goto LangCodeOK
}
}
}
Gui Hide
TitleString:=GetLang(133) . " " . ln ; Unknown language code for layout: %ln%
LangCode:= KBD_Lang%kk%
TempString:= GetLang(127) . " " . LangCode . " " . GetLang(134) . "`n" . GetLang(135) . "`n`n" . GetLang(136) ; "The language code " . %LangCode% . " is unknown on this computer, and you have not configured an alternative for this keyboard.`nSome applications may not function properly with this language.`n`nLoad it anyway?"
MsgBox 4, %TitleString%, %TempString%
Gui Show
ifmsgbox Yes
goto LangCodeOK
KBD_Disabled%kk% := 1
goto ProcessKbdErrors
}
LangCodeOK:
; Identify the keyboard file settings
local ff := InStr(KbdFiles, ":" . KBD_File%kk% . A_Tab)
if (ff) {
KBD_FileID%kk% := substr(KbdFiles, ff - 4, 4) + 0
} else {
numKbdFiles++
KBD_FileID%kk% := numKbdFiles
kFileName%numKbdFiles% := KBD_File%kk%
KbdFiles .= " " . KBD_FileID%kk% . ":" . KBD_File%kk% . A_Tab
}
; first 4 parameters are K_ProtocolNum, InKeyHwnd, FileID, KbdId
RunCmd%kk% := GetAHKCmd(KBD_File%kk%) . """" . KBD_AhkFile%kk% . """ " . K_ProtocolNum . " " . selfHwnd . " " . KBD_FileID%kk% . " " . kk . " " . KBD_Params%kk%
klid := FindKLID(KBD_LayoutName%kk%, KBD_Lang%kk%) ; See if keyboard named is registered
;outputdebug FindKLID => %klid%.
if (klid) {
; Keyboard is registered. Ensure we haven't already used it.
if (InStr(ProcdKbdList, klid)) {
Gui Hide ; TODO: Add this text to Lang
MsgBox 0, % "Keyboard Configuration Error", % "Each keyboard must have a unique layout name.`n`nKeyboard File: " KBD_Folder%kk% "\" KBD_IniStem%kk% "`nLayout name: " KBD_LayoutName%kk% "`n`nCheck keyboard settings."
Gui Show
KBD_Disabled%kk% := 1
goto ProcessKbdErrors
}
ProcdKbdList .= klid . " "
;Ensure it's loaded, and get its HKL.
KBD_HKL%kk% := LoadKeyboardLayout(klid, 16, KBD_LayoutName%kk%)
oKbdByHKL[KBD_HKL%kk%] := kk
;~ Outputdebug % "Kbd# " . kk . " uses registered KLID: " . klid . ", HKL=" . KBD_HKL%kk% ;%
} else {
; Keyboard is not registered.
if (PortableMode) {
KBD_HKL%kk% := LoadSubstituteKeyboard(KBD_Lang%kk%, KBD_LayoutName%kk%) ; Use a non-registered keyboard instead.
oKbdByHKL[KBD_HKL%kk%] := kk
} else {
; Remember this keyboard as one we need to register (once all keyboard settings have been read).
Kbd2RegCt++
Kbd2Reg%Kbd2RegCt% := kk
}
}
} else {
; These are the settings for a non-InKey keyboard (e.g. System or Keyman etc)
; Set KbdFile[], KbdKLID[] and KbdHKL[] values
KBD_File%kk% := ""
KBD_FileID%kk% =
if (not KbdKLID%kk%)
KbdKLID%kk% = 00000409
KBD_HKL%kk% := LoadKeyboardLayout(KbdKLID%kk%)
oKbdByHKL[KBD_HKL%kk%] := kk
Outputdebug % "Kbd# " . kk . " is NON-INKEY. KLID=" . KbdKLID%kk% . ", HKL=" . KBD_HKL%kk% ;%
}
;ChangeLanguage(KBD_HKL%kk%) ; Should help refresh the Lang Bar
local hkl := KBD_HKL%kk%
;~ HKLDisplayName%hkl% := RegExReplace(KBD_MenuText%kk%, "&") ; Strip the ampersand
oHKLDisplayName[hkl] := RegExReplace(KBD_MenuText%kk%, "&") ; Strip the ampersand
; Icon settings for this keyboard
KbdIconFile%kk% := KBD_Icon%kk%
if (KbdIconFile%kk%) {
; If there is a second parameter (after a comma), separate that out.
if (RegExMatch(KbdIconFile%kk%, "(.*),\s*(.*)", val)) {
KbdIconFile%kk% = %val1%
KBD_IconNum%kk% = %val2%
}
; If the icon file exists in the keyboard's folder, prepend path.
if (FileExist(KBD_Folder%kk% . "\" . KbdIconFile%kk%))
KbdIconFile%kk% := KBD_Folder%kk% . "\" . KbdIconFile%kk%
; otherwise hopefully the file is a system DLL
}
KBD_Icon%kk% =
local ii := KBD_MenuText%kk%
menu KbdMenu, add, %ii%, KeyboardMenuItem ; Add menu item for this keyboard
}
RegisterAndLoadKeyboard(kk) {
global
local Lang := KBD_Lang%kk%
local layoutName := KBD_LayoutName%kk%
local hiword
local dummy
local hkl
local jj
; Find the first available KLID for this lang
SetFormat, IntegerFast, H
Loop 255
{
hiword := A_Index ; save as hex
KLID := substr("000" . substr(hiword, 3), -3) . Lang
RegRead dummy, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%KLID%, Layout File
if (ErrorLevel)
break
}
StringUpper KLID, KLID
; Set ID according to the next number after MaxLID
MaxLID++
SetFormat, IntegerFast, d
ID := substr("000" . substr(MaxLID, 3), -3) ; e.g. 0xE -> 000E, 0x9E2 -> 09E2
StringUpper ID, ID
; Set the HKL. "F" followed by last 3 chars of ID followed by Lang's 4 chars
hkl := "0xF" . substr(ID,-2) . Lang
; Write the registry settings for this layout
OutputDebug Writing to registry: %KLID%, %ID%, %layoutName%, %UnderlyingLayoutFile%.
RegWrite REG_SZ, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%KLID%, InKey, 1
RegWrite REG_SZ, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%KLID%, layout file, %UnderlyingLayoutFile%
RegWrite REG_SZ, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%KLID%, layout id, %ID%
RegWrite REG_SZ, HKLM, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%KLID%, layout text, %layoutName%
if errorlevel {
Outputdebug RegWrite failed
return 0
}
if (0) ; if (Preload) ; TODO: I don't remember what Preload was supposed to mean
RegisterForPreloading(KLID, Lang) ; so this NEVER gets called!!
jj := LoadKeyboardLayout(KLID, 16, layoutName)
if (jj <> hkl) {
Outputdebug % "Error loading new kbd# " . A_Index . ". Expected HKL: " . hkl . ". Got HKL: " . jj ; %
return 0
} else {
Outputdebug % "Kbd# " . A_Index . " succesfully registered. LN=" . layoutName . ", KLID=" . klid . ", HKL=" . hkl ;%
}
return hkl
}
RegisterForPreloading(KLID, Lang) {
; Check if there is a Substitutes item whose data value is already this KLID
SubstID := ""
Loop HKCU, Keyboard Layout\Substitutes
{ RegRead rKLID
if (rKLID = KLID) {
SubstID := A_LoopRegName
break
}
}
; If not found, create one.
if (not SubstID) {
setformat integerfast, h
substNum := 0x0
Loop {
SubstID := "d" . substr("00" . substr(substNum,3), -2) . Lang
RegRead itExists, HKCU, Keyboard Layout\Substitutes, %SubstID%
if ErrorLevel
break ; we've found an available SubstID
substNum++
}
setformat integerfast, d
RegWrite REG_SZ, HKCU, Keyboard Layout\Substitutes, %SubstID%, %KLID%
}
; Check that there is not already a preload for this substID
PreloadID := ""
Loop HKCU, Keyboard Layout\Preload
{ RegRead rSubstID
if (rSubstID = SubstID) {
PreloadID := A_LoopRegName
break
}
}
; If not found, create one.
if (not PreloadID) {
PreloadID := GetNextPreload()
RegWrite REG_SZ, HKCU, Keyboard Layout\Preload, %PreloadID%, %SubstID%
}
}
GetNextPreload() { ; Retrieve the last preload number
static n = 0
if (n <> 0)
return n++
Loop HKCU, Keyboard Layout\Preload
{ n := A_LoopRegName + 1
break
}
return n
}
GetAHKCmd(filename) {
if (SubStr(filename, -3) <> ".ahk")
return "" ; Not an AHK file. Must be an EXE. We'll just run the file as specified.
return GetAHK() . " "
}
GetAHK() {
global
static RunAHK := ""
static ahkexe := "AutoHotKey.EXE"
if (RunAHK)
return RunAHK
if (FileExist(A_ScriptDir . "\" . ahkexe)) {
RunAHK := ahkexe
return RunAHK
}
;~ if (FileExist(A_AHKPath)) {
;~ RunAHK := A_AHKPath
;~ return RunAHK
;~ }
gui hide
TitleString:=GetLang(137) ; InKey Installation Error. Please reinstall.
MsgBox 16, ERROR, %TitleString%
ExitApp
}
ProcessTinkerFile(kk) { ; Generate an AHK file from the TINKER file
global
tinkWarnings := 0
local TinkerFile := KBD_TinkerFile%kk%
local AHKFile := KBD_AhkFile%kk%
outputdebug Generating %AHKFile% from %TinkerFile%
FileEncoding UTF-8
FileRead tinkerLines, %TinkerFile%
if (ErrorLevel) {
return ("Unable to read file: " TinkerFile)
}
layoutLines := ""
if (KBD_DisplayCmdSrc%kk%) {
FileRead layoutLines, % KBD_DisplayCmdSrc%kk%
layoutLines := RegExReplace(layoutLines, "i)((?:〔)|〔)LayoutName(〕|(?:〕))", KBD_LayoutName%kk%)
layoutLines := RegExReplace(layoutLines, "i)((?:〔)|〔)IniFileName(〕|(?:〕))", KBD_IniFile%kk%)
; layoutLines := RegExReplace(layoutLines, "i)KA", "k")
}
tinkerLines := RegExReplace(tinkerLines, "((?<!\r)\n)|(\r(?!\n))", "`r`n") ; ensure canonical CR-LF
tinkerLines := RegExReplace(tinkerLines, "[\x{a0}]+", " ") ; replace any no break space with normal space. (may be code copied from tutorial.)
; local nbsp := chr(0xA0)
; StringReplace tinkerLines, tinkerLines, %nbsp%, %A_Space%, 1 ; replace any no break space with normal space. (may be code copied from tutorial.)
; Remove all comments and trailing whitespace from the file
local fpos
while (fpos := RegExMatch(tinkerLines, "(【[^【】]*)//([^【】]*】)")) { ; First preserve all // that are inside 【 param braces 】
tinkerLines := RegExReplace(tinkerLines, "(【[^【】]*)//([^【】]*】)", "$1" chr(0xfffe) "$2", 0, -1, fpos)
}
tinkerLines := RegExReplace(tinkerLines, "\s*//.*", "") ; nuke comments
StringReplace tinkerLines, tinkerLines, % chr(0xfffe), //, 1
tinkerLines := RegExReplace(tinkerLines, "m)\s+$", "") ; nuke trailing whitespace
tinkerLines := RegExReplace(tinkerLines, "s)(►.*?◄)", "")
tinkerLines := RegExReplace(tinkerLines, "(?<=\n)[\r\n]+", "") ; nuke blank lines
if (FileExist(AHKFile)) {
FileDelete %AHKFile%
}
FileAppend `; generated by InKey v. %ver%`n, %AHKFile%
local CapsSensitive := 1
local options := ""
local CapsKeys := "abcdefghijklmnopqrstuvwxyz"
fpos := RegExMatch(tinkerLines, "Oim)^Settings:\s*(?:\s+//.*)?\r?\n((?:\s+.*\r?\n)+)(?:Options:\s*(?:\s+//.*)?\r?\n((?:\s+.*\r?\n)+))?\.\.\.(?:\s+//.*)?\r?\n", match)
if (fpos) {
tinkerLines := SubStr(tinkerLines, match.Len(0) + fpos)
local settings := match.Value(1)
options := match.Value(2)
; Check Tinker version for compatibility
if (RegExMatch(settings, "Om)^\s+TinkerVersion:\s+([0-9\.]*)$", match)) {
local tvNum := versionNum(match.Value(1))
if (tvNum < K_MinTinkerVersion) {
local err := TinkerFile " uses Tinker v. " match.Value(1) ". Please update keyboard to at least v. " K_MinTinkerVersion
FileAppend `; %err%`n, %AHKFile%
return (err)
}
if (tvNum > K_TinkerVersion) {
local err := TinkerFile " requires a later version of InKey (" match.Value(1) "). Please update InKey version " ver " to the latest version."
FileAppend `; %err%`n, %AHKFile%
return (err)
}
} else {
TinkWarnings += 1
FileAppend `; WARNING: No TinkerVersion key found in Settings`n, %AHKFile%
}
; Get CapsSensitive setting
if (RegExMatch(settings, "Om)^\s+CapsSensitive:\s+(No|false)$", match)) {
CapsSensitive := 0
}
; Get CapsKeys setting
if (RegExMatch(settings, "Om)^\s+CapsKeys:\s+(\S*)$", match)) {
CapsKeys := match.Value(1)
}
} else {
local fp := InStr(tinkerLines, "...")
if (fp) {
tinkerLines := SubStr(tinkerLines, fp+1)
FileAppend `; WARNING: Error in parsing header section`n, %AHKFile%
tinkWarnings += 1
} else {
FileAppend `; ERROR: Unable to locate '...' marking end of header in:%tinkerLines%`n, %AHKFile%
return ("Unable to locate '...' marking end of header in " TinkerFile)
}
}
; parse the Options section
local fldName
local fldDef
local fldVal
local optionsFile := KBD_CacheStem%kk% . ".options"
if (FileExist(optionsFile)) {
FileDelete %optionsFile%
}
if (options) {
FileAppend %options%, %optionsFile%
while (StrLen(options) > 1) {
if (RegExMatch(options, "Oi)^( +)- (checkbox|keystroke):\s*\r?\n((?:\1\s+.*\r?\n)+)", match)) {
options := substr(options, match.Len(0)+1)
local ctrltype := match.Value(2)
local subFlds := match.Value(3)
fldName := ""
if (RegExMatch(subFlds, "Oi) name:\s+(.*?)\r?\n", match)) {
fldName := match.Value(1)
} else {
FileAppend /* WARNING: Option not parsed:`n%subFlds% */, %AHKFile%
continue
}
fldDef := " "
if (RegExMatch(subFlds, "Oi) default:\s+(.*?)\r?\n", match)) {
fldDef := match.Value(1)
}
; numOpts += 1
; OPT_Name%numOpts% := fldName