-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicRoutines.ahk
1925 lines (1650 loc) · 51.3 KB
/
BasicRoutines.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
;========================================================
; Basic routines for free SIL keyboards
; Created 2009 by Johann Schaumberger, SIL
; Version 12.Feb.2010
; E-mail Hans_Schaumberger@sil.org
;========================================================
; This file contains the wrapper for the keyboard
; you should not modify any part of this file
#NoEnv
; Basic variables:
; Special keys, which will break modifiers:
sInternalKey1 = $Space
sInternalKey2 = $Up
sInternalKey3 = $Down
sInternalKey4 = $Left
sInternalKey5 = $Right
sInternalKey6 = $Tab
sInternalKey7 = $Enter
sInternalKey8 = $Esc
sInternalKey9 = $Home
sInternalKey10 = $End
sInternalKey11 = $PgUp
sInternalKey12 = $PgDn
sInternalKey13 = $+Space
sInternalCount = 13
HandleWhitespace := 1
SequenceMarker := "_"
MatrixMarker := ","
ElementMarker := "|"
; Content of the "About dialog"
sAbout1 := ""
sAbout2 := "Free " %sName% " keyboard"
sAbout3 := "Based on 'Auto Hotkey' script"
sAbout4 := "Written by Johann Schaumberger (SIL)"
sAbout5 := ""
sAbout6 := "Errors and wishes please report to:"
sAbout7 := "Hans_Schaumberger@sil.org"
sAbout8 := "Version 2.0"
sAbout9 := ""
; Default settings:
iUseKeyboard := 0 ; Is the Language keyboard used? 0= no 1 = yes
iRecogLanguage := 0 ; Is Language switching on 0= no 1 = yes
sKeyLangName := "" ; Name of language to switch language keyboard on
sDeflangName := "" ; Name of language to switch language keyboard off
iKeyID := -1 ; ID of language keyboard
iDefID := -1 ; ID of default language keyboard
iHotShiftOn := 0
iHotALtOn := 0
iHotCtrlOn := 0
sHotKeyOnL := ""
sHotKeyOn := "" ; Shortcut key to switch keyboard on
iHotShiftOff := 0
iHotALtOff := 0
iHotCtrlOff := 0
sHotKeyOffL := ""
sHotKeyOff := "" ; Shortcut key to switch keyboard off
iOnlyOff := -1 ; Does only the default language switch the keyboard off?
iCompMode := 0
; KEYBOARD DEFINITIONS
; Definitions for keys which should be used, add others if needed
; Basic keys:
x := "%"
sKey = abcdefghijklmnopqrstuvwxyz1234567890?!<>=-_.#*,|{}[]/\^%x%~@$+&:;'"()
; Keys together with {SHIFT}
sShiftKey = abcdefghijklmnopqrstuvwxyz
; Keys together with {ALT} (Needed for non-englisch keyboards!!!)
sAltKey = {}[]$@()~
; Special keys if wanted:
sSpecialKey := ""
; Unique ID for identifying the keyboard, (a random number)
Random, iKeyboardID, 1, 0xfffffff
MSGNum := WM_COMMAND && 0x46c
MouseNum := WM_COMMAND && 0x201
Debug := 0
InitUnicode()
KeyboardName()
PrepareValues()
sSettingFile = %sName%Keyboard.txt
sIconOn = %sName%On.ico ; Don't modify
sIconOff = %sName%Off.ico ; Don't modify
KeyingDocument = %A_WorkingDir%\%sName%KeyboardMap.pdf
IfNotExist, %sName%KeyboardMap.pdf
{
FileAppend %sName% Keyboard `n No mapping available , %sName%KeyboardMap.pdf
}
IfNotExist, %sSettingFile%
{
WriteSettings()
}
CheckIfAutostart() ; Autostart on
CreateKeys()
CreateMenuAndDialog()
ReadSettings()
; Create the shortcut keys
if (sHotKeyOnL <> "" && sHotKeyOnL <> "(none)")
Hotkey, %sHotKeyOnL%, DoHotkeyOn,UseErrorLevel
if (sHotKeyOffL <> "" && sHotKeyOffL <> "(none)" )
Hotkey, %sHotKeyOffL%, DoHotkeyOff,UseErrorLevel
SetWorkingDir, %A_ScriptDir%
SwitchLanguage("Off")
SetTimer, Timer, 500 ; Set timer for dedecting language swithes
OnMessage(0x404,"AHK_NotifyTrayIcon") ; Check for left click on tray icon
OnMessage(%MSGNum%,"AHK_LanguageSwitch") ; Check for language changes through mouseclick
AHK_NotifyTrayIcon(wParam, lParam)
{
global
If lParam = 0x201
ShowTrayPopup()
return
}
AHK_LanguageSwitch(wParam, lParam, msg)
{
Global
if (wParam == 5555) ; switch off other languages
{
if (lParam <> iKeyboardID)
SwitchLanguage("Off")
}
else if (wParam == 5545) ; Compatibility mode on or off?
{
iCompMode := lParam
if (iCompMode == 1)
Menu, Menu1, Check, Compatibility mode
else
Menu, Menu1, Uncheck, Compatibility mode
WriteSettings()
}
}
;========================================================
; Timer routine
;========================================================
Timer:
SetFormat, Integer, H
WinGet, WinID,, A
ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", 0)
InputLocaleID:=DllCall("GetKeyboardLayout", "Int", ThreadID)
language := InputLocaleID & 0x0000ffff
if (iRecogLanguage = 1)
{
if (Language <> lastLanguage)
{
if (language = iKeyID)
SwitchLanguage("On")
else if (language = iDefID)
SwitchLanguage("Off")
else
if (iOnlyOff = 1)
SwitchLanguage("Off")
}
}
LastLanguage := Language
return
~*LButton::
LastKey := ""
LastOutput := ""
MatrixKey := ""
return
SwitchTimer(mode)
{
global
if (mode = "1")
{
SetTimer, Timer, On
iRecogLanguage := 1
}
else
{
SetTimer, Timer, Off
iRecogLanguage := 0
}
}
; ===============================================================================================
; Unicode sending routines:
; ===============================================================================================
; Prepare settings for single character Unicode sending routine
InitUnicode()
{
Global
DllCall("LoadLibrary", "str", "ntoskrnl.exe")
SendU4 := 4 << 16 ; KEYEVENTF_UNICODE
SendU6 := 6 << 16 ; KEYEVENTF_KEYUP|KEYEVENTF_UNICODE
VarSetCapacity( SendUbuf, 56, 0 )
DllCall("RtlFillMemory", "uint",&SendUbuf, "uint",1, "uint", 1)
DllCall("RtlFillMemory", "uint",&SendUbuf+28, "uint",1, "uint", 1)
VarSetCapacity(UText, 4, 0 )
VarSetCapacity(AText, 4, 0 )
}
; Send a single character
SendUnicode( p_uchar ) ; 3 DllCalls, needs one prior call to SendUinit()
{
Global
if (iCompMode = 0)
{
DllCall("ntoskrnl.exe\RtlFillMemoryUlong", "uint",&SendUbuf+6, "uint",4, "uint", p_uchar | SendU4)
DllCall("ntoskrnl.exe\RtlFillMemoryUlong", "uint",&SendUbuf+34, "uint",4, "uint", p_uchar | SendU6)
Return DllCall( "SendInput", "uint", 2, "uint", &SendUbuf, "int", 28 )
}
else
{
NumPut(p_uchar, UText, 0, "UShort")
DllCall("WideCharToMultiByte"
, "UInt", 65001 ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
, "UInt", 0 ; dwFlags
, "Str", UText ; LPCWSTR lpWideCharStr
, "Int", -1 ; cchWideChar: size in WCHAR values: Len or -1 (= null terminated)
, "Str", AText ; LPSTR lpMultiByteStr
, "Int", 4 ; cbMultiByte: Len or 0 (= get required size / allocate!)
, "UInt", 0 ; LPCSTR lpDefaultChar
, "UInt", 0) ; LPBOOL lpUsedDefaultChar
Critical
Transform Clipboard, %AText%
ClipWait 1
SendInput ^v
Sleep, 50
Critical, Off
}
}
; Sends a whole unicode string
SendUnicodeString( p_text )
{
Global
if (iCompMode = 0)
{
;msgbox %p_text%
event_count := ( StrLen(p_text)//4 )*2
VarSetCapacity( events, 28*event_count, 0 )
base = 0
Loop % event_count//2 ;%
{
StringMid code, p_text, 4*A_Index-3, 4
code = 0x4%code%
DllCall("RtlFillMemory", "uint", &events + base, "uint",1, "uint", 1)
DllCall("ntoskrnl.exe\RtlFillMemoryUlong", "uint",&events+base+6, "uint",4, "uint",code)
base += 28
DllCall("RtlFillMemory", "uint", &events + base, "uint",1, "uint", 1)
DllCall("ntoskrnl.exe\RtlFillMemoryUlong", "uint",&events+base+6, "uint",4, "uint",code|(2<<16))
base += 28
}
result := DllCall( "SendInput", "uint", event_count, "uint", &events, "int", 28 )
}
else
{
;msgbox %p_text%
count := strlen(p_text) //4
;msgbox %count%
out := ""
loop %count%
{
value := substr(p_text, 4*A_Index -3, 4)
value = 0x%value%
;msgbox %value%
NumPut(value, UText, 0, "UShort")
DllCall("WideCharToMultiByte"
, "UInt", 65001 ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
, "UInt", 0 ; dwFlags
, "Str", UText ; LPCWSTR lpWideCharStr
, "Int", -1 ; cchWideChar: size in WCHAR values: Len or -1 (= null terminated)
, "Str", AText ; LPSTR lpMultiByteStr
, "Int", 4 ; cbMultiByte: Len or 0 (= get required size / allocate!)
, "UInt", 0 ; LPCSTR lpDefaultChar
, "UInt", 0) ; LPBOOL lpUsedDefaultChar
out = %out%%Atext%
; msgbox %Atext%
}
Critical
Transform Clipboard, %out%
ClipWait 1
SendInput ^v
Sleep, 50
Critical, Off
}
}
;========================================================
;Language routines
;========================================================
SwitchLanguage(what)
{
Global
if (what = "On")
{
TurnKeysOn()
Menu, tray, icon, %sIconOn%, 1, 0
;Menu, tray, icon, %sIconOn%
iUseKeyboard := 0
PostMessage, %MSGNum%,5555,iKeyboardID,, ahk_id 0xFFFF
}
else
{
TurnKeysOff()
Menu, tray, icon, %sIconOff%, 1, 0
;Menu, tray, icon, %sIconOff%
iUseKeyboard := 1
}
}
;========================================================
; Switching keyboards
;========================================================
SwitchKeyboard(which)
{
Global
if (which = "On")
TurnKeysOn()
else
TurnKeysOff()
}
;========================================================
; Keyboard on and off shortcut routine
;========================================================
DoHotkeyOn:
SwitchLanguage("On")
return
DoHotkeyOff:
SwitchLanguage("Off")
PostMessage, %MSGNum%,5555,iKeyboardID,, ahk_id 0xFFFF
return
;========================================================
; Creating, switching on and off keys
;========================================================
; -------------------------------------------------------
CreateKeys()
{
Global
a := 0 ; Single keystrokes
StringLen, z, sKey
loop, %z%
{
a := a + 1
x := SubStr(sKey,a,1)
x = $%x% ; The $ must be to avoid an endless "receive-send key" loop
Hotkey, %x%, KeyBasicDown,UseErrorLevel
}
a := 0 ; Capital letters
StringLen, z, sShiftKey
loop, %z%
{
a := a + 1
x := SubStr(sShiftKey,a,1)
x = $+%x%
Hotkey, %x%, KeyShiftDown,UseErrorLevel
}
a := 0 ; Keystrokes which need {ALT} (on non-english keyboards)
StringLen,z, sAltKey
loop, %z%
{
a := a + 1
x := SubStr(sAltKey,a,1)
x = <^>%x%
Hotkey, %x%, KeyAltDown,UseErrorLevel
}
if (sSpecialKey <> "")
{
find := "|"
start := 0
myloopcreate1:
StringGetPos, start, sSpecialKey, %find%,, start
ende := start + 1
StringGetPos, ende, sSpecialKey, %find%,, ende
if (ende <> -1)
{
length := ende - start
t := Substr(sSpecialKey, start + 2, length - 1)
Hotkey, %t%, KeyBasicDown,UseErrorLevel
start := start + 1
goto myloopcreate1
}
}
if (HandleWhitespace <> 0)
{
loop %sInternalcount%
{
hk := sInternalKey%A_Index%
Hotkey %hk% , KeySpecialDown,UseErrorLevel
}
}
}
; -------------------------------------------------------
TurnKeysOn()
{
Global
a := 0 ; Single keystrokes
StringLen, z, sKey
loop, %z%
{
a := a + 1
x := SubStr(sKey,a,1)
x = $%x%
Hotkey, %x%, on,UseErrorLevel
}
a := 0 ; Capital letters
StringLen, z, sShiftKey
loop, %z%
{
a := a + 1
x := SubStr(sShiftKey,a,1)
x = $+%x%
Hotkey, %x%, on,UseErrorLevel
}
a := 0 ; Keystrokes which need {ALT}
StringLen,z, sAltKey
loop, %z%
{
a := a + 1
x := SubStr(sAltKey,a,1)
x = <^>%x%
Hotkey, %x%, on,UseErrorLevel
}
find := "|"
start := 0
if (sSpecialKey <> "")
{
myloopon1:
StringGetPos, start, sSpecialKey, %find%,, start
ende := start + 1
StringGetPos, ende, sSpecialKey, %find%,, ende
if (ende <> -1)
{
length := ende - start
t := Substr(sSpecialKey, start + 2, length - 1)
Hotkey, $%t%, on
start := start + 1
goto myloopon1
}
}
if (HandleWhitespace <> 0)
{
Hotkey $Space, on
Hotkey $Up, on
Hotkey $Down, on
Hotkey $Left, on
Hotkey $Right, on
Hotkey $Tab, on
Hotkey $Enter, on
Hotkey $Esc, on
Hotkey $Home, on
Hotkey $End, on
Hotkey $PgUp, on
Hotkey $PgDn, on
}
}
; -------------------------------------------------------
TurnKeysOff()
{
Global
a := 0
StringLen,z, sKey
loop, %z%
{
a := a + 1
x := SubStr(sKey,a,1)
x = $%x%
Hotkey, %x%, off,UseErrorLevel
}
a := 0
StringLen, z, sShiftKey
loop, %z%
{
a := a + 1
x := SubStr(sShiftKey,a,1)
x = $+%x%
Hotkey, %x%, off,UseErrorLevel
}
a := 0
StringLen, z, sAltKey
loop, %z%
{
a := a + 1
x := SubStr(sAltKey,a,1)
x = <^>%x%
Hotkey, %x%, off,UseErrorLevel
}
find := "|"
start := 0
if (sSpecialKey <> "")
{
myloopoff1:
StringGetPos, start, sSpecialKey, %find%,, start
ende := start + 1
StringGetPos, ende, sSpecialKey, %find%,, ende
if (ende <> -1)
{
length := ende - start
t := Substr(sSpecialKey, start + 2, length - 1)
Hotkey, $%t%, off,UseErrorLevel
start := start + 1
goto myloopoff1
}
}
if (HandleWhitespace <> 0)
{
Hotkey $Space, off
Hotkey $Up, off
Hotkey $Down, off
Hotkey $Left, off
Hotkey $Right, off
Hotkey $Tab, off
Hotkey $Enter, off
Hotkey $Esc, off
Hotkey $Home, off
Hotkey $End, off
Hotkey $PgUp, off
Hotkey $PgDn, off
}
}
KeyBasicDown:
LastKey := A_ThisHotkey
KeyFired := False
KeyDown(A_ThisHotkey)
DefaultKey()
return
KeyShiftDown:
StringRight, t, A_ThisHotkey, 1
StringUpper, t, t
what = $%t%
LastKey := what
KeyFired := False
KeyDown(what)
DefaultKey()
return
KeyAltDown:
StringRight, t, A_ThisHotkey, 1
what = $%t%
LastKey := what
KeyFired := False
KeyDown(what)
DefaultKey()
return
KeySpecialDown:
StringTrimLeft s,A_ThisHotkey,1
Send {%s%}
;msgbox %s%
if (debug == 0)
{
LastKey := ""
LastOutput := ""
MatrixKey := ""
}
AddOutputSequence(A_ThisHotkey)
return
; ======================================================================================
;
; Dialog routines and Tray menu items
;
; ======================================================================================
; Reads the keyboard settings from a textfile,
; which is in the same folder as the program;
; The Registry is not used since it would give problems
; when running the program from a flashdrive
ReadSettings()
{
Global
FileReadLine, iUseKeyboard, %sSettingFile%, 1
FileReadLine, iRecogLanguage, %sSettingFile%, 2
FileReadLine, sKeyLangName, %sSettingFile%, 3
FileReadLine, sDefLangName, %sSettingFile%, 4
FileReadLine, iKeyID, %sSettingFile%, 5
FileReadLine, iDefID, %sSettingFile%, 6
FileReadLine, iHotShiftOn, %sSettingFile%, 7
FileReadLine, iHotAltOn, %sSettingFile%, 8
FileReadLine, iHotCtrlOn, %sSettingFile%, 9
FileReadLine, sHotKeyOn, %sSettingFile%, 10
FileReadLine, iHotShiftOff, %sSettingFile%, 11
FileReadLine, iHotAltOff, %sSettingFile%, 12
FileReadLine, iHotCtrlOff, %sSettingFile%, 13
FileReadLine, sHotKeyOff, %sSettingFile%, 14
FileReadLine, iOnlyOff, %sSettingFile%, 15
FileReadLine, sHotKeyOnL, %sSettingFile%, 16
FileReadLine, sHotKeyOffL, %sSettingFile%, 17
FileReadLine, iCompMode, %sSettingFile%, 18
if (sHotkeyOn = "")
sHotKeyOn := "(none)"
if (sHotkeyOff = "")
sHotKeyOff := "(none)"
}
; Writes the keyboard settings to a textfile,
; which is in the same folder as the program;
WriteSettings()
{
Global
FileDelete, %sSettingFile%
FileAppend,
(
%iUseKeyboard%
%iRecogLanguage%
%sKeyLangName%
%sDefLangName%
%iKeyID%
%iDefID%
%iHotShiftOn%
%iHotALtOn%
%iHotCtrlOn%
%sHotKeyOn%
%iHotShiftOff%
%iHotALtOff%
%iHotCtrlOff%
%sHotKeyOff%
%iOnlyOff%
%sHotKeyOnL%
%sHotKeyOffL%
%iCompMode%
), %sSettingFile%
}
CreateMenuAndDialog()
{
Global
; ==============================================================
; Create the popup menu for the keyboard selection:
; ==============================================================
Menu, tray, NoStandard ; Remove all standard options
Menu, tray, add, Help ... , ShowHelp ;
Menu, tray, add, Options... , OptionHandler ; Option dialog item
Menu, tray, add, About... , AboutHandler ; About dialog item
Menu, tray, Add ; Creates a separator line.
Menu, tray, Add, Suspend, SuspendHandler ; Add a suspend item
Menu, tray, Add, Exit, ExitHandler ; Add the exit item
; ==============================================================
; Create Tray menu items
; ==============================================================
Menu, Menu1, Add, %sName%, KeyboardOn
Menu, Menu1, Add, No keyboard, KeyboardOff
MI_SetMenuItemIcon("Menu1", 1, sIconOn, 1, 16)
Menu, Menu1, Add
Menu, Menu1, Add, Compatibility mode, CompMode ; Compatibility mode
Menu, Menu1, Add
Menu, Menu1, Add, Show keying document, ShowKeyboardDocument ; Show the keyboarding document
; ==============================================================
; Option dialog box:
; ==============================================================
shortcut = (none)|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|w|y|z
Gui, Add, Tab2,x10 y10 w250 h350, Basic Settings | Language switches ; Tab2 vs. Tab requires v1.0.47.05.
Gui, Tab, 1
Gui, Add, Text
Gui, Add, Checkbox, vdStartCheckboxVar , Start keyboard with Windows
Gui, Add, Text
Gui, Add, Checkbox, vdCompMode , Compatibility mode
Gui, Add, Text
Gui, Add, Text
Gui, Add, Text,, Hotkey for %sName%
Gui, Add, Checkbox, x20 y150 w50 h15 vdOnAlt, ALT
Gui, Add, Checkbox, x90 y150 w50 h15 vdOnControl, CTRL
Gui, Add, Checkbox, x160 y150 w50 h15 vdOnShift, SHIFT
Gui, Add, DropDownlist, x20 y180 w150 h100 vdKeyOn, %shortcut%
,
Gui, Add, Text
Gui, Add, Text,, Hotkey for switching off keyboard
Gui, Add, Checkbox, x20 y255 w50 h15 vdOffAlt, ALT
Gui, Add, Checkbox, x90 y255 w50 h15 vdOffControl, CTRL
Gui, Add, Checkbox, x160 y255 w50 h15 vdOffShift, SHIFT
Gui, Add, DropDownlist, x20 y285 w150 h100 vdKeyOff, %shortcut%
Gui, Tab, 2
Gui, Add, Text
Gui, Add, Checkbox, vdRecogLanguage , Switch keyboard with language
Gui, Add, Text
Gui, Add, Text,, Select the switch language for %sName%
Gui, Add, DropDownList, w200 vdKeyLangName
Gui, Add, Text
Gui, Add, Text,, Default language to switch off keyboards
Gui, Add, Radio,vdOnlyOff, All languages switch off
Gui, Add, Radio,vdOnlyThis, Only this language switches off:
Gui, Add, DropDownList, w200 vdDefLangName
Gui, Tab
Gui, Add, Button, default xm, OK
; =============================================================
; "About" dialog box
; ==============================================================
Gui 2: Add, Text,, %sAbout1%
Gui 2: Add, Text,, %sAbout2%
Gui 2: Add, Text,, %sAbout3%
Gui 2: Add, Text,, %sAbout4%
Gui 2: Add, Text,, %sAbout5%
Gui 2: Add, Text,, %sAbout6%
Gui 2: Add, Text,, %sAbout7%
Gui 2: Add, Text,, %sAbout8%
Gui 2: Add, Text,, %sAbout9%
}
ReadInstalledLanguages()
{
Global
GUIControl,,dKeyLangName, | ; Clear content of Language listboxes
GUIControl,,dDefLangName, |
loop HKEY_CURRENT_USER, Keyboard Layout\Preload,0,0
{
RegRead Locale
StringRight, loc, locale, 3
locale := "0x" locale
VarSetCapacity(name, 128, 32)
Lang := DllCall("GetLocaleInfoW"
,Uint, Locale
,Uint, 2 ; &H2 = 'localized name of language
,Str, name
,UInt, 128)
;msgbox locale name: %name%
if (strlen(name) < 120)
{
GUIControl,,dKeyLangName, %loc% %name%
GUIControl,,dDefLangName, %loc% %name%
}
}
}
ExitHandler:
ExitApp
return
SuspendHandler:
suspend toggle
return
KeyboardOn:
SwitchLanguage("On")
return
KeyboardOff:
SwitchLanguage("Off")
return
CompMode:
if (iCompMode == 0)
{
iCompMode := 1
Menu, Menu1, Check, Compatibility mode
}
else
{
iCompMode := 0
Menu, Menu1, Uncheck, Compatibility mode
}
PostMessage, %MSGNum%,5545,iCompMode,, ahk_id 0xFFFF ; Inform other scripts about the current mode
return
ShowKeyboardDocument:
if (KeyingDocument <> A_WorkingDir)
{
ifExist %KeyingDocument%
{
Run, open %KeyingDocument%
}
}
return
ShowHelp:
{
ifExist %A_WorkingDir%\freekey.chm
{
Run, open %A_WorkingDir%\freekey.chm
}
else
Msgbox Sorry, no helpfile available
}
return
OptionHandler:
ReadSettings()
CheckIfAutostart()
ReadInstalledLanguages()
GuiControl,, dStartCheckboxVar, %iAutostartOn%
GuiControl,, dCompMode, %iCompMode%
GuiControl,, dOnAlt, %iHotALtOn%
GuiControl,, dOnControl, %iHotCtrlOn%
GuiControl,, dOnShift, %iHotShiftOn%
GuiControl, ChooseString, dKeyOn, %sHotKeyOn%
GuiControl,, dOffAlt, %iHotALtOff%
GuiControl,, dOffControl, %iHotCtrlOff%
GuiControl,, dOffShift, %iHotShiftOff%
GuiControl, ChooseString, dKeyOff, %sHotKeyOff%
GuiControl,, dRecogLanguage, %iRecogLanguage%
GuiControl, ChooseString, dKeyLangName, %sKeyLangName%
GuiControl, ChooseString, dDefLangName, %sDefLangName%
if (iOnlyOff = 0)
GuiControl,, dOnlyThis, 1
else
GuiControl,, dOnlyOff, 1
Gui, Show
return
AboutHandler:
Gui 2: Show
return
ButtonOK:
GuiClose:
GuiEscape:
Gui, Submit ; Save each control's contents to its associated variable.
SetOptionDialogSettings()
return
ShowTrayPopup()
{
Menu, Menu1, Show
}
SetOptionDialogSettings()
{
Global
; Basic setting:
SwitchTimer(dRecogLanguage)
Setautostart(dStartCheckboxVar)
iOnlyOff := dOnlyOff
iCompMode := dCompMode
PostMessage, %MSGNum%,5545,iCompMode,, ahk_id 0xFFFF ; Inform other scripts about the current mode
if (dKeyLangName <> "")
if (dKeyLangName <> sKeyLangName)
{
StringLeft, iKeyID, dKeyLangName, 3
iKeyID := "0x"iKeyID
sKeyLangName := dKeyLangName
}
if (dDefLangName <> "")
if (dDefLangName <> sDefLangName)
{
StringLeft iDefID, dDefLangName, 3
iDefID := "0x"iDefID
sDefLangName := dDefLangName
}
CreateHotkeys()
WriteSettings() ; Save settings to file
}
CreateHotkeys()
{
Global
; Destroy old hotkeys first
if (sHotKeyOnL <> "" && sHotKeyOnL <> "(none)")
Hotkey, %sHotKeyOnL%, off,UseErrorLevel
if (sHotKeyOffL <> "" && sHotKeyOffL <> "(none)" )
Hotkey, %sHotKeyOffL%, off,UseErrorLevel
iHotALtOn := dOnAlt,
iHotCtrlOn := dOnControl,
iHotShiftOn := dOnShift,
sHotKeyOn := dKeyOn,
iHotALtOff := dOffAlt,
iHotCtrlOff := dOffControl,
iHotShiftOff := dOffShift,
sHotKeyOff := dKeyOff,
if (dKeyOn <> "(none)")
{
x := ""
if (dOnAlt = 1)
x = !
if (dOnControl = 1)
x = %x%^
if (dOnShift = 1)
x = %x%+
x = %x%%dKeyOn%
sHotKeyOnL := x
Hotkey, %x%, DoHotkeyOn,UseErrorLevel
Hotkey, %x%, On
}
else
sHotKeyOnL := ""
if (dKeyOff <> "(none)")
{
x := ""
if (dOffAlt = 1)
x = !
if (dOffControl = 1)
x = %x%^
if (dOffShift = 1)
x = %x%+
x = %x%%dKeyOff%
sHotKeyOffL := x