-
Notifications
You must be signed in to change notification settings - Fork 52
/
KBLAutoSwitch.ahk
3177 lines (2940 loc) · 131 KB
/
KBLAutoSwitch.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
/*tong(【自动切换输入法】)
版本: v2.4.1
脚本: KBLAutoSwitch自动切换输入法
作者: tong
*/
Label_ScriptSetting: ; 脚本前参数设置
Process, Priority, , Realtime ;脚本高优先级
#MenuMaskKey vkE8
#Persistent ;让脚本持久运行(关闭或ExitApp)
#SingleInstance Force ;允许多例运行,通过Single_Run限制单例
#WinActivateForce ;强制激活窗口
#MaxHotkeysPerInterval 2000 ;时间内按热键最大次数
#HotkeyModifierTimeout 100 ;按住modifier后(不用释放后再按一次)可隐藏多个当前激活窗口
SetBatchLines, -1 ;脚本全速执行
SetControlDelay -1 ;控件修改命令自动延时,-1无延时,0最小延时
CoordMode Menu Window ;坐标相对活动窗口
CoordMode Mouse Screen ;鼠标坐标相对于桌面(整个屏幕)
ListLines, Off ;不显示最近执行的脚本行
SendMode Input ;更速度和可靠方式发送键盘点击
SetTitleMatchMode 2 ;窗口标题模糊匹配;RegEx正则匹配
DetectHiddenWindows on ;显示隐藏窗口
SetWorkingDir, %A_ScriptDir%
Label_DefVar: ; 初始化变量
global StartTick:=A_TickCount ; 启动开始时间
global ScriptIniting := 1 ; 脚本初始化中
global APPName := "KBLAutoSwitch"
global APPVersion := "2.4.0"
global APPVersion := "2.4.1"
global INI := A_ScriptDir "\KBLAutoSwitch.ini" ; 配置文件
global AutoSwitchFrequency := 0 ; 自动切换次数统计
global APPType := RegExMatch(APPVersion, "\d*\.\d*\.\d*\.\d*")?"(测试版)":"",APPVersion := APPVersion APPType
; 固定变量初始化
global State_ShowTime := 1000 ; 信息提示时间
global FontType := "Microsoft YaHei" ; 字体类型
global CN_Code:=0x804,EN_Code:=0x409 ; KBL代码
global Display_Cn := "中",Display_CnEn := "英",Display_En := "En" ; KBL提示信息
global Auto_Reload_MTime:=2000 ; 自动重载时间
; 创建INI配置文件参数变量
global Auto_Launch,Launch_Admin,Auto_Switch,Default_Keyboard
global TT_OnOff_Style,TT_Display_Time,TT_Font_Size,TT_Transparency,TT_Shift,TT_Pos_Coef
global Tray_Display,Tray_Display_KBL,Tray_Double_Click,Tray_Display_Style
global Disable_HotKey_App_List,Disable_Switch_App_List,Disable_TTShow_App_List,No_TwiceSwitch_App_List,FocusControl_App_List
global Cur_Launch,Cur_Launch_Style,Cur_Size
global Hotkey_Add_To_Cn,Hotkey_Add_To_CnEn,Hotkey_Add_To_En,Hotkey_Remove_From_All
global Hotkey_Set_Chinese,Hotkey_Set_ChineseEnglish,Hotkey_Set_English,Hotkey_Display_KBL,Hotkey_Reset_KBL,Hotkey_Toggle_CN_CNEN,Hotkey_Toggle_CN_EN
global Hotkey_Stop_KBLAS,Hotkey_Get_KeyBoard
global Hotkey_Left_Shift,Hotkey_Right_Shift,Hotkey_Left_Ctrl,Hotkey_Right_Ctrl,Hotkey_Left_Alt,Hotkey_Right_Alt
global Open_Ext,Outer_InputKey_Compatible,Left_Mouse_ShowKBL,Left_Mouse_ShowKBL_Up,SetTimer_Reset_KBL,Reset_CapsLock,Enter_Inputing_Content,GuiTTColor,TrayTipContent,AutoCheckUpdate
global LatestCheckDateTime
global Custom_Win_Group,Custom_Hotstring
global INI_CN,INI_CNEN,INI_EN
Label_AdminLaunch: ; 管理员启动
iniread, Launch_Admin, %INI%, 基本设置, 管理员启动, 1
if (!A_IsAdmin && Launch_Admin=1)
{
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}catch{
MsgBox, 1,, 以【管理员权限】启动失败!将以普通权限启动,管理员应用窗口将失效!
IfMsgBox OK
{
if A_IsCompiled
Run "%A_ScriptFullPath%" /restart
else
Run "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
}
ExitApp
}
Label_SystemVersion: ; 获取win系统版本
global OSVersion := StrReplace(A_OSVersion, ".")
If (OSVersion="WIN_7")
OSVersion := 7
Else If (OSVersion<10022000)
OSVersion := 10
Else If (OSVersion>=10022000)
OSVersion := 11
Else
OSVersion := 0
Label_WindowsMonitor: ; 获取windows显示器信息
OnMessage(0x007E, "monitorChange")
SysGet, MonitorCount, MonitorCount
global MonitorAreaObjects := Object()
Loop, %MonitorCount%
{
SysGet, Monitor, Monitor, %A_Index%
MonitorAreaObject := Object()
MonitorAreaObject[1] := MonitorLeft
MonitorAreaObject[2] := MonitorTop
MonitorAreaObject[3] := MonitorRight
MonitorAreaObject[4] := MonitorBottom
MonitorAreaObject[5] := Abs(MonitorRight-MonitorLeft)<Abs(MonitorBottom-MonitorTop)?Abs(MonitorRight-MonitorLeft):Abs(MonitorBottom-MonitorTop)
MonitorAreaObjects[A_Index] := MonitorAreaObject
}
Label_SystemVersion_Var: ; 设置win系统版本对应变量
global Ico_path := Object()
global Ico_num := Object()
If (OSVersion=10){
Ico_path["关闭菜单"] := "imageres.dll",Ico_num["关闭菜单"] := 233
Ico_path["帮助文档"] := "imageres.dll",Ico_num["帮助文档"] := 100
Ico_path["检查更新"] := "shell32.dll",Ico_num["检查更新"] := 14
Ico_path["语言首选项"] := "imageres.dll",Ico_num["语言首选项"] := 110
Ico_path["设置"] := "shell32.dll",Ico_num["设置"] := 317
Ico_path["关于"] := "imageres.dll",Ico_num["关于"] := 77
Ico_path["停止"] := "imageres.dll",Ico_num["停止"] := 208
Ico_path["重启"] := "imageres.dll",Ico_num["重启"] := 229
Ico_path["退出"] := "imageres.dll",Ico_num["退出"] := 230
}Else If (OSVersion=11){
Ico_path["关闭菜单"] := "imageres.dll",Ico_num["关闭菜单"] := 234
Ico_path["帮助文档"] := "imageres.dll",Ico_num["帮助文档"] := 110
Ico_path["检查更新"] := "shell32.dll",Ico_num["检查更新"] := 14
Ico_path["语言首选项"] := "imageres.dll",Ico_num["语言首选项"] := 110
Ico_path["设置"] := "shell32.dll",Ico_num["设置"] := 315
Ico_path["关于"] := "imageres.dll",Ico_num["关于"] := 77
Ico_path["停止"] := "imageres.dll",Ico_num["停止"] := 208
Ico_path["重启"] := "imageres.dll",Ico_num["重启"] := 230
Ico_path["退出"] := "imageres.dll",Ico_num["退出"] := 231
}Else If (OSVersion=7){
Ico_path["关闭菜单"] := "imageres.dll",Ico_num["关闭菜单"] := 102
Ico_path["帮助文档"] := "imageres.dll",Ico_num["帮助文档"] := 110
Ico_path["检查更新"] := "shell32.dll",Ico_num["检查更新"] := 14
Ico_path["语言首选项"] := "imageres.dll",Ico_num["语言首选项"] := 110
Ico_path["设置"] := "imageres.dll",Ico_num["设置"] := 64
Ico_path["关于"] := "imageres.dll",Ico_num["关于"] := 77
Ico_path["停止"] := "imageres.dll",Ico_num["停止"] := 207
Ico_path["重启"] := "shell32.dll",Ico_num["重启"] := 239
Ico_path["退出"] := "shell32.dll",Ico_num["退出"] := 216
}Else If (OSVersion=0){
Ico_path["关闭菜单"] := "shell32.dll",Ico_num["关闭菜单"] := 3
Ico_path["帮助文档"] := "shell32.dll",Ico_num["帮助文档"] := 3
Ico_path["检查更新"] := "shell32.dll",Ico_num["检查更新"] := 14
Ico_path["语言首选项"] := "shell32.dll",Ico_num["语言首选项"] := 3
Ico_path["设置"] := "shell32.dll",Ico_num["设置"] := 3
Ico_path["关于"] := "shell32.dll",Ico_num["关于"] := 3
Ico_path["停止"] := "shell32.dll",Ico_num["停止"] := 3
Ico_path["重启"] := "shell32.dll",Ico_num["重启"] := 3
Ico_path["退出"] := "shell32.dll",Ico_num["退出"] := 3
}
Label_KBLDetect: ; 从注册表检测KBL
KBLObj := Object()
Loop, Reg, HKEY_CURRENT_USER\Keyboard Layout\Preload, V
{
RegRead, OutputVar
OutputVar := SubStr(OutputVar,-2)
KBLObj[OutputVar] := 1
}
If KBLObj.HasKey(804){
If KBLObj.HasKey(409)
KBLEnglish_Exist := 1
Else
KBLEnglish_Exist := 0
}Else{
MsgBox,16,,未安装【中文】输入法,请安装中文输入法后重试!
ExitApp
}
Label_ReadINI: ; 读取INI配置文件
if !FileExist(INI)
Gosub,Label_Init_INI
; 读取基本设置
iniread, Auto_Launch, %INI%, 基本设置,开机自启, 0
iniread, Auto_Switch, %INI%, 基本设置, 自动切换, 1
iniread, Default_Keyboard, %INI%, 基本设置, 默认输入法, 1
iniread, TT_OnOff_Style, %INI%, 基本设置, 切换提示, 4
iniread, TT_Display_Time, %INI%, 基本设置, 切换提示时间, 1500
iniread, TT_Font_Size, %INI%, 基本设置, 切换提示文字大小, 15,30
iniread, TT_Transparency, %INI%, 基本设置, 切换提示透明度, 235,180
iniread, TT_Shift, %INI%, 基本设置, 切换提示偏移, 0,0
iniread, TT_Pos_Coef, %INI%, 基本设置, 切换提示固定位置, 50,30
iniread, Tray_Display, %INI%, 基本设置,托盘图标显示, 1
iniread, Tray_Double_Click, %INI%, 基本设置,托盘图标双击, 2
iniread, Tray_Display_KBL, %INI%, 基本设置,托盘图标显示输入法, 1
iniread, Tray_Display_Style, %INI%, 基本设置,托盘图标样式, 原版
iniread, Cur_Launch, %INI%, 基本设置,鼠标指针显示输入法, 1
iniread, Cur_Launch_Style, %INI%, 基本设置,鼠标指针样式, 原版
iniread, Cur_Size, %INI%, 基本设置,鼠标指针对应分辨率, 0
; 读取屏蔽窗口列表
iniread, Disable_HotKey_App_List, %INI%, 热键屏蔽窗口列表
iniread, Disable_Switch_App_List, %INI%, 切换屏蔽窗口列表
iniread, Disable_TTShow_App_List, %INI%, 切换提示屏蔽窗口列表
iniread, No_TwiceSwitch_App_List, %INI%, 二次切换屏蔽窗口列表
iniread, FocusControl_App_List, %INI%, 焦点控件切换窗口列表
; 读取热键
iniread, Hotkey_Add_To_Cn, %INI%, 热键设置,添加至中文窗口, %A_Space%
iniread, Hotkey_Add_To_CnEn, %INI%, 热键设置,添加至英文(中文)窗口, %A_Space%
iniread, Hotkey_Add_To_En, %INI%, 热键设置,添加至英文输入法窗口, %A_Space%
iniread, Hotkey_Remove_From_All, %INI%, 热键设置,移除从中英文窗口, %A_Space%
iniread, Hotkey_Set_Chinese, %INI%, 热键设置,切换中文, %A_Space%
iniread, Hotkey_Set_ChineseEnglish, %INI%, 热键设置,切换英文(中文), %A_Space%
iniread, Hotkey_Set_English, %INI%, 热键设置,切换英文输入法, %A_Space%
iniread, Hotkey_Toggle_CN_CNEN, %INI%, 热键设置,切换中英文(中文), %A_Space%
iniread, Hotkey_Toggle_CN_EN, %INI%, 热键设置,切换中英文输入法, %A_Space%
iniread, Hotkey_Display_KBL, %INI%, 热键设置,显示当前输入法, %A_Space%
iniread, Hotkey_Reset_KBL, %INI%, 热键设置,重置当前输入法, %A_Space%
iniread, Hotkey_Stop_KBLAS, %INI%, 热键设置,停止自动切换, %A_Space%
iniread, Hotkey_Get_KeyBoard, %INI%, 热键设置,获取输入法IME代码, %A_Space%
; 读取特殊热键
iniread, Hotkey_Left_Shift, %INI%, 特殊热键,左Shift, 1
iniread, Hotkey_Right_Shift, %INI%, 特殊热键,右Shift, 2
iniread, Hotkey_Left_Ctrl, %INI%, 特殊热键,左Ctrl, 0
iniread, Hotkey_Right_Ctrl, %INI%, 特殊热键,右Ctrl, 0
iniread, Hotkey_Left_Alt, %INI%, 特殊热键,左Alt, 0
iniread, Hotkey_Right_Alt, %INI%, 特殊热键,右Alt, 0
; 读取高级设置
iniread, Open_Ext, %INI%, 高级设置, 内部关联, %A_Space%
iniread, Outer_InputKey_Compatible, %INI%, 高级设置, 快捷键兼容, 1
iniread, Left_Mouse_ShowKBL, %INI%, 高级设置, 左键点击输入位置显示输入法状态, 1|全局窗口
iniread, Left_Mouse_ShowKBL_Up, %INI%, 高级设置, 左键弹起后提示输入法状态生效窗口, Code.exe
iniread, SetTimer_Reset_KBL, %INI%, 高级设置, 定时重置输入法, 60|编辑器
iniread, Reset_CapsLock, %INI%, 高级设置, 切换重置大小写, 1
iniread, Enter_Inputing_Content, %INI%, 高级设置, 上屏字符内容, 2|1
iniread, GuiTTColor, %INI%, 高级设置, 提示颜色, 333434|dfe3e3|02ecfb|ff0000
iniread, TrayTipContent, %INI%, 高级设置, 托盘提示内容, %A_Space%
iniread, AutoCheckUpdate, %INI%, 高级设置, 自动检查更新, 0
; 读取自定义窗口组和自定义操作
iniread, Custom_Win_Group, %INI%, 自定义窗口组
iniread, Custom_Hotstring, %INI%, 自定义操作
; 读取分组
iniread, INI_CN, %INI%, 中文窗口
IniRead, INI_CNEN, %INI%, 英文窗口
IniRead, INI_EN, %INI%, 英文输入法窗口
; 读取信息变量
iniread, LatestCheckDateTime, %INI%, 信息变量, 最近检查更新日期, 2000-01-01 00:00:00
; 设置自定义窗口组
global WinMenuObj := Object()
global Custom_Win_Group_Cn,Custom_Win_Group_CnEn,Custom_Win_Group_En
global groupNameList := "无",groupNameObj := Object(),groupNumObj := Object()
groupNameObj["无"] := 0
groupNumObj[0] := "无"
Loop, parse, Custom_Win_Group, `n, `r
{
MyVar := StrSplit(Trim(A_LoopField), "=")
groupNum := MyVar[1]
groupName := MyVar[2]
groupState := MyVar[3]
groupVal := MyVar[4]
groupNameList .= "|" groupName
groupNameObj[groupName] := groupNum
groupNumObj[groupNum] := groupName
getINISwitchWindows(groupVal,groupName,"|")
If (Auto_Switch=1){ ; 添加自定组到自动切换组
Switch groupState
{
Case 1:GroupAdd, cn_ahk_group_custom, ahk_group%A_Space%%groupName%
Case 2:GroupAdd, cnen_ahk_group_custom, ahk_group%A_Space%%groupName%
Case 3:GroupAdd, en_ahk_group_custom, ahk_group%A_Space%%groupName%
}
}
}
; 设置自动切换输入法窗口组
If (Auto_Switch=1) {
getINISwitchWindows(INI_CN,"cn_ahk_group") ; 中文输入法中文模式窗口
getINISwitchWindows(INI_CNEN,"cnen_ahk_group") ; 中文输入法英文文模式窗口
If (KBLEnglish_Exist=0)
getINISwitchWindows(INI_EN,"cnen_ahk_group") ; 英文输入法窗口
Else
getINISwitchWindows(INI_EN,"en_ahk_group") ; 英文输入法窗口
;-------------------------------------------------------
; 不切换窗口组
GroupAdd, unswitch_ahk_group, ahk_class tooltips_class32 ; 任务栏小箭头
GroupAdd, unswitch_ahk_group_after, ahk_class Qt5QWindowToolSaveBits
GroupAdd, unswitch_ahk_group_after, ahk_class Windows.UI.Core.CoreWindow
GroupAdd, unswitch_ahk_group_after, ahk_exe HipsTray.exe
GroupAdd, unswitch_ahk_group_after, ahk_exe rundll32.exe
GroupAdd, unswitch_ahk_group_before, ahk_class MultitaskingViewFrame ; alt+tab切换
GroupAdd, unswitch_ahk_group_before, ahk_class TaskListThumbnailWnd ; 窗口缩略图
GroupAdd, unswitch_ahk_group_before, ahk_class Shell_TrayWnd ; 任务栏
GroupAdd, unswitch_ahk_group_before, ahk_class NotifyIconOverflowWindow ; 任务栏小箭头
}
; 默认焦点控件窗口
GroupAdd, focus_control_ahk_group, ahk_exe ApplicationFrameHost.exe ; uwp应用
GroupAdd, focus_control_ahk_group, ahk_exe explorer.exe ; 文件资源管理器
; 获取输入光标位置sleep组
GroupAdd, GetCaretSleep_ahk_group, ahk_class Chrome_WidgetWin_1 ; Chromium类应用
; 输入法输入候选窗口
GroupAdd, IMEInput_ahk_group, ahk_class SoPY_Comp ; 搜狗输入法
GroupAdd, IMEInput_ahk_group, ahk_class SoWB_Comp ; 搜狗五笔输入法
GroupAdd, IMEInput_ahk_group, ahk_class QQWubiCompWndII ; QQ五笔输入法
GroupAdd, IMEInput_ahk_group, ahk_class QQPinyinCompWndTSF ; QQ拼音输入法
GroupAdd, IMEInput_ahk_group, ahk_class PalmInputUICand ; 手心输入法
GroupAdd, IMEInput_ahk_group, ahk_class i)^ATL: ; 冰凌五笔输入法
Label_DisableAppList: ; 读取屏蔽窗口列表
getINISwitchWindows(Disable_HotKey_App_List,"DisableHotKeyAppList_ahk_group") ; 热键屏蔽
getINISwitchWindows(Disable_Switch_App_List,"DisableSwitchAppList_ahk_group") ; 切换屏蔽
getINISwitchWindows(Disable_TTShow_App_List,"DisableTTShowAppList_ahk_group") ; 切换提示屏蔽
getINISwitchWindows(No_TwiceSwitch_App_List,"NoTwiceSwitchAppList_ahk_group") ; 二次切换屏蔽窗口列表
getINISwitchWindows(FocusControl_App_List,"focus_control_ahk_group")
Label_Hotstring: ; 自定义操作
global TarFunList := Object(),TarHotFunFlag := 0
Loop, parse, Custom_Hotstring, `n, `r
{
MyVar := StrSplit(Trim(A_LoopField), "=")
TargroupName := groupNumObj[MyVar[2]]
TarHotFlag := SubStr(MyVar[3], 1, 2)
TarHotVal := SubStr(MyVar[3], 3)
Hotkey, IfWinActive, ahk_group%A_Space%%TargroupName%
Loop, parse, TarHotVal, "|"
{
TarFunList[A_LoopField] := MyVar[4]
If (TarHotFlag="s-")
Hotstring(":*XB0:" A_LoopField, "TarHotFun")
Else If (TarHotFlag="k-")
try Hotkey, %A_LoopField%, TarHotFun
}
}
Label_ReadExtRunList: ; 读取内部关联
If (Open_Ext!=""){
global openExtRunList := Object() ; 内部关联路径加参数
global openExtRunList_Parm := Object() ; 内部关联参数
global openExtRunList_num := ReadExtRunList(Open_Ext,"ini|folder") ; 读取内部关联返回数量
}
Label_IcoLaunch: ; 根据Win明暗主题设置图标所在路径
Gosub, Label_ReadExistIcoStyles
global SystemUsesLightTheme
RegRead, SystemUsesLightTheme, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
SystemUsesLightTheme_Str := SystemUsesLightTheme=0?"black":"white"
If (Tray_Display=1 && Tray_Display_KBL=1){
ACNico_path = %A_ScriptDir%\Icos\%Tray_Display_Style%\%SystemUsesLightTheme_Str%_A_CN.ico
AENico_path = %A_ScriptDir%\Icos\%Tray_Display_Style%\%SystemUsesLightTheme_Str%_A_EN.ico
CNico_path = %A_ScriptDir%\Icos\%Tray_Display_Style%\%SystemUsesLightTheme_Str%_Cn.ico
CNENico_path = %A_ScriptDir%\Icos\%Tray_Display_Style%\%SystemUsesLightTheme_Str%_CnEn.ico
ENico_path = %A_ScriptDir%\Icos\%Tray_Display_Style%\%SystemUsesLightTheme_Str%_En.ico
global ACNIcon := LoadPicture(ACNico_path,,ImageType)
global AENIcon := LoadPicture(AENico_path,,ImageType)
global CNIcon := LoadPicture(CNico_path,,ImageType)
global CNENIcon := LoadPicture(CNENico_path,,ImageType)
global ENIcon := LoadPicture(ENico_path,,ImageType)
}
Label_CurLaunch: ; 鼠标指针初始化
Gosub, Label_ReadExistCurStyles
global ExistCurSize := "" ; 鼠标指针分辨率字符串
Loop Files, %A_ScriptDir%\Curs\%Cur_Launch_Style%\*, D
ExistCurSize := ExistCurSize "|" A_LoopFileName
If (Cur_Launch=1){
global OCR_IBEAM := 32513,OCR_NORMAL := 32512,OCR_APPSTARTING := 32650,OCR_WAIT := 32514,OCR_HAND := 32649
global OCR_CROSS:=32515,OCR_HELP:=32651,OCR_NO:=32648,OCR_UP:=32516
global OCR_SIZEALL:=32646,OCR_SIZENESW:=32643,OCR_SIZENS:=32645,OCR_SIZENWSE:=32642,OCR_SIZEWE:=32644
global CurPathObjs := Object()
Loop, % MonitorAreaObjects.Length(){
If (ExistCurSize=""){
realWindowsHeight := 0
}Else{
WindowsHeight := MonitorAreaObjects[A_Index][5]
realWindowsHeight := WindowsHeight
}
If (!FileExist(A_ScriptDir "\Curs\" Cur_Launch_Style "\" realWindowsHeight)){
Loop, parse, ExistCurSize, |
{
If (A_Index=1)
Continue
Else If (A_Index=2)
realWindowsHeight := A_LoopField
Else
realWindowsHeight := Abs(A_LoopField-WindowsHeight)<Abs(WindowsHeight-realWindowsHeight)?A_LoopField:realWindowsHeight
}
}
If (Cur_Size)
realWindowsHeight := Cur_Size
MonitorAreaObjects[A_Index][5] := realWindowsHeight
CurPathObjs[MonitorAreaObjects[A_Index][5]] := 1
}
For k, v in CurPathObjs{
CurPathObj := Object()
CurPathObj[1] := getCurPath(Cur_Launch_Style,k,"IBEAM_Cn_A")
CurPathObj[2] := getCurPath(Cur_Launch_Style,k,"IBEAM_En_A")
CurPathObj[3] := getCurPath(Cur_Launch_Style,k,"IBEAM_Cn")
CurPathObj[4] := getCurPath(Cur_Launch_Style,k,"IBEAM_En")
CurPathObj[5] := getCurPath(Cur_Launch_Style,k,"NORMAL_Cn_A")
CurPathObj[6] := getCurPath(Cur_Launch_Style,k,"NORMAL_En_A")
CurPathObj[7] := getCurPath(Cur_Launch_Style,k,"NORMAL_Cn")
CurPathObj[8] := getCurPath(Cur_Launch_Style,k,"NORMAL_En")
CurPathObj[9] := getCurPath(Cur_Launch_Style,k,"APPSTARTING")
CurPathObj[10] := getCurPath(Cur_Launch_Style,k,"WAIT")
CurPathObj[11] := getCurPath(Cur_Launch_Style,k,"HAND")
CurPathObj[12] := getCurPath(Cur_Launch_Style,k,"CROSS")
CurPathObj[13] := getCurPath(Cur_Launch_Style,k,"HELP")
CurPathObj[14] := getCurPath(Cur_Launch_Style,k,"NO")
CurPathObj[15] := getCurPath(Cur_Launch_Style,k,"UP")
CurPathObj[16] := getCurPath(Cur_Launch_Style,k,"SIZEALL")
CurPathObj[17] := getCurPath(Cur_Launch_Style,k,"SIZENESW")
CurPathObj[18] := getCurPath(Cur_Launch_Style,k,"SIZENS")
CurPathObj[19] := getCurPath(Cur_Launch_Style,k,"SIZENWSE")
CurPathObj[20] := getCurPath(Cur_Launch_Style,k,"SIZEWE")
CurPathObjs[k] := CurPathObj
}
}
Label_AutoRun: ; 开机自启
SplitPath, A_ScriptName , , , , OutNameNoExt
RegRead, Auto_Launch_reg, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, %OutNameNoExt%
Auto_Launch_reg := Auto_Launch_reg=A_ScriptDir "\" OutNameNoExt ".exe" ? 1 : 0
If(Auto_Launch!=Auto_Launch_reg){
Auto_Launch_reg:=Auto_Launch
If(Auto_Launch){
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, %OutNameNoExt%, %A_ScriptDir%\%OutNameNoExt%.exe
}Else{
RegDelete, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, %OutNameNoExt%
}
}
Label_NecessaryVar: ; 定义必要变量
global lastKBLCode56,LastKBLState56 ; 切换输入法标志
global shellMessageFlag := 1 ; 窗口切换标志
global NextChangeFlag := 0 ; 下次切换标志
global CheckDateTimeInterval := 0 ; 距离上次检查更新天数
global AutoCheckOnceFlag := 1 ; 一次检测更新标志
global KBLTempFilePath := A_Temp "\KBLAutoSwitch.ahk"
global KBLDownloadPath := A_Temp "\KBLDownload.ahk"
global SwitchTT_id,TT_Edit_Hwnd,TT_Edit_Hwnd1 ; Gui和控件句柄
global LastKBLState,LastCapsState,LastMonitorNum,gl_Active_IMEwin_id ; 前一个KBL、大小写、屏幕编号状态,及激活窗口IME句柄
; 默认输入法调整
global Real_Default_Keyboard := Default_Keyboard
If (KBLEnglish_Exist=0 && Default_Keyboard=3)
Real_Default_Keyboard := 2
GuiTTColorObj := StrSplit(GuiTTColor, "|") ; Gui颜色
global GuiTTBackCnColor:=GuiTTColorObj[1],GuiTTBackEnColor:=GuiTTColorObj[2],GuiTTCnColor:=GuiTTColorObj[3],GuiTTEnColor:=GuiTTColorObj[4]
Enter_Inputing_ContentObj := StrSplit(Enter_Inputing_Content, "|") ; 上屏
global Enter_Inputing_Content_Core := Enter_Inputing_ContentObj[1],Enter_Inputing_Content_CnTo := Enter_Inputing_ContentObj[2]
global ImmGetDefaultIMEWnd := DllCall("GetProcAddress", "Ptr", DllCall("LoadLibrary", "Str", "imm32", "Ptr"), "AStr", "ImmGetDefaultIMEWnd", "Ptr")
; 网络信息获取文本地址
global AppInfoUrl := "https://gitee.com/flyinclouds/KBLAutoSwitch/raw/master/AppInfo.txt"
; 自定义变量
global 启动时间 := A_YYYY "/" A_MM "/" A_DD " " A_Hour ":" A_Min ":" A_Sec
global 权限 := A_IsAdmin=1?"管理员":"非管理员"
global 版本 := "v" APPVersion
global 启动时长 := 0
; 网络信息获取
global 最新版本 := "v0.0.0"
global 交流群 := "https://jq.qq.com/?_wv=1027&k=A3F0yfcy"
global 交流群信息 := "548517941【KBLAutoSwitch交流群】"
global 帮助文档 := "https://docs.qq.com/doc/DWHFxVXBNbWNxcWpa"
global 下载地址 := "https://wwr.lanzoui.com/b02i9dmsd"
global 下载地址提取码 := "fd5v"
global github地址 := "https://github.com/flyinclouds/KBLAutoSwitch"
Label_DropDownListData: ; 下拉列表数据
global OnOffState := "禁止|开启"
global KBLSwitchState := "无|中文|英文(中文)|英文"
global TrayFuncState := "无|语言首选项|设置|停止"
global OperationState := "无|切换至中文|切换至英文(中文)|切换至英文输入法|切换中英文(中文)|切换中英文输入法|重置输入法"
global ListViewKBLState := "无|中|英(中)|英"
global DefaultCapsLockState := "无|小写|大写"
Label_Init: ; 初始化操作
Gosub, Label_Init_ShowKBLGui ; 初始化切换显示GUI
Gosub, Label_Init_ResetINI ; 定时检测配置文件
Label_Left_Mouse_ShowKBL: ; 左键显示输入法
StrSplit(Left_Mouse_ShowKBL,"|",,2)
Left_Mouse_ShowKBL_temp := StrSplit(Left_Mouse_ShowKBL,"|",,2)
Left_Mouse_ShowKBL_State := Left_Mouse_ShowKBL_temp[1]
getINISwitchWindows(Left_Mouse_ShowKBL_temp[2],"Left_Mouse_ShowKBL_WinGroup","|")
Hotkey, IfWinActive, ahk_group Left_Mouse_ShowKBL_WinGroup
If (Left_Mouse_ShowKBL_State=1 && TT_OnOff_Style!=0){
Hotkey, ~LButton, Label_Click_showSwitch
Hotkey, ~WheelUp, Label_Hide_All
Hotkey, ~WheelDown, Label_Hide_All
}
getINISwitchWindows(Left_Mouse_ShowKBL_Up,"Left_Mouse_ShowKBL_Up_WinGroup","|")
Label_CreateHotkey: ; 创建热键
Hotkey, IfWinNotActive, ahk_group DisableHotKeyAppList_ahk_group
if (Hotkey_Add_To_Cn != "")
Hotkey, %Hotkey_Add_To_Cn%, Add_To_Cn
if (Hotkey_Add_To_CnEn != "")
Hotkey, %Hotkey_Add_To_CnEn%, Add_To_CnEn
if (Hotkey_Add_To_En != "")
Hotkey, %Hotkey_Add_To_En%, Add_To_En
if (Hotkey_Remove_From_All != "")
Hotkey, %Hotkey_Remove_From_All%, Remove_From_All
if (Hotkey_Set_Chinese != ""){
TarFunList[Hotkey_Set_Chinese] := 1
try Hotkey, %Hotkey_Set_Chinese%, TarHotFun
}
if (Hotkey_Set_ChineseEnglish != ""){
TarFunList[Hotkey_Set_ChineseEnglish] := 2
try Hotkey, %Hotkey_Set_ChineseEnglish%, TarHotFun
}
if (Hotkey_Set_English != ""){
TarFunList[Hotkey_Set_English] := 3
try Hotkey, %Hotkey_Set_English%, TarHotFun
}
if (Hotkey_Toggle_CN_CNEN != ""){
TarFunList[Hotkey_Toggle_CN_CNEN] := 4
try Hotkey, %Hotkey_Toggle_CN_CNEN%, TarHotFun
}
if (Hotkey_Toggle_CN_EN != ""){
TarFunList[Hotkey_Toggle_CN_EN] := 5
try Hotkey, %Hotkey_Toggle_CN_EN%, TarHotFun
}
if (Hotkey_Reset_KBL != ""){
TarFunList[Hotkey_Reset_KBL] := 6
try Hotkey, %Hotkey_Reset_KBL%, TarHotFun
}
if (Hotkey_Display_KBL != "")
Hotkey, %Hotkey_Display_KBL%, Display_KBL
if (Hotkey_Stop_KBLAS != "")
Hotkey, %Hotkey_Stop_KBLAS%, Stop_KBLAS
if (Hotkey_Get_KeyBoard != "")
Hotkey, %Hotkey_Get_KeyBoard%, Get_KeyBoard
Label_BoundHotkey: ; 绑定特殊热键
If (Outer_InputKey_Compatible=1)
extraKey := " Up"
BoundHotkey("~LShift" extraKey,Hotkey_Left_Shift)
BoundHotkey("~RShift" extraKey,Hotkey_Right_Shift)
BoundHotkey("~LControl" extraKey,Hotkey_Left_Ctrl)
BoundHotkey("~RControl" extraKey,Hotkey_Right_Ctrl)
BoundHotkey("~LAlt" extraKey,Hotkey_Left_Alt)
BoundHotkey("~RAlt" extraKey,Hotkey_Right_Alt)
Label_SetTimer: ; 定时器等功能
If (KBLObj.Length()>1){ ; 定时KBL状态检测
If (Tray_Display=1)
try Gosub, Label_Create_Tray
If ((Tray_Display=1 && Tray_Display_KBL=1) || Cur_Launch=1 || TT_OnOff_Style!=0){
Gosub, Label_KBLState_Detect
SetTimer, Label_KBLState_Detect, 100
}
}
; 定时重置输入法
SetTimer_Reset_KBL_temp := StrSplit(SetTimer_Reset_KBL,"|",,2)
SetTimer_Reset_KBL_Time := SetTimer_Reset_KBL_temp[1]
getINISwitchWindows(SetTimer_Reset_KBL_temp[2],"SetTimer_Reset_KBL_WinGroup","|")
global Reset_CapsLock_State := SubStr(Reset_CapsLock, 1, 1)
getINISwitchWindows(SubStr(Reset_CapsLock, 3),"Inner_AHKGroup_NoCapsLock","|")
Label_AutoSwitch: ; 监听窗口切换输入法
DllCall("ChangeWindowMessageFilter", "UInt", 0x004A, "UInt" , 1) ; 接受非管理员权限RA消息
If (Auto_Switch=1){ ; 监听窗口消息
DllCall("RegisterShellHookWindow", UInt, A_ScriptHwnd)
global shell_msg_num := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
OnMessage(shell_msg_num, "shellMessage")
shellMessage(1,1)
}
OnMessage(0x004A, "Receive_WM_COPYDATA")
Label_End: ; 收尾工作
OnExit("ExitFunc") ; 退出执行
VarSetCapacity(Ico_path, 0)
VarSetCapacity(Ico_num, 0)
ScriptIniting := 0 ; 脚本初始化结束
启动时长 := Round((A_TickCount-StartTick)/1000,3) " 秒"
Gosub, Label_Change_TrayTip ; 更新托盘提示
SetTimer, Label_GetLatestAppInfo, -10 ; 获取最新信息
SetTimer, Label_ClearMEM, -1000 ; 清理内存
Label_Return: ; 结束标志
Return
;-----------------------------------【程序启动功能】-----------------------------------------------
Label_KBLState_Detect: ; 输入法状态检测
showSwitch()
Return
ExitFunc() { ; 退出执行-还原鼠标指针
DllCall( "SystemParametersInfo", "UInt",0x57, "UInt",0, "UInt",0, "UInt",0 ) ;还原鼠标指针
Gosub, Label_CloseKBLDownload
}
Label_Change_TrayTip: ; 改变托盘图标提示
自动切换次数 := Format("{:d}", AutoSwitchFrequency/2)
Transform, TrayTipContent_new, Deref, % TrayTipContent
TrayTipContent_new := TrayTipContent_new=""?"KBLAutoSwitch":TrayTipContent_new
Menu, Tray, Tip, %TrayTipContent_new%
Return
Label_GetLatestAppInfo: ; 获取最新信息
try{
AppInfo := UrlDownloadToVar(AppInfoUrl)
Loop, parse, AppInfo, `n, `r ; 在 `r 之前指定 `n, 这样可以同时支持对 Windows 和 Unix 文件的解析.
{
word_array := StrSplit(A_LoopField, ":",,2)
varName := word_array[1]
varValue := word_array[2]
try SetEnv, %varName%, %varValue%
}
}catch e {
最新版本 := "v0.0.0"
}
Gosub, Label_Change_TrayTip ; 更新托盘提示
If (AutoCheckOnceFlag=1){
AutoCheckOnceFlag := 0
If (AutoCheckUpdate!=0)
Gosub, Label_AutoCheckUpdate
}
Return
Label_AutoCheckUpdate: ; 自动检测更新提示
Gosub, Label_UpdateCheckDateTimeInterval
If (CheckDateTimeInterval!="" && CheckDateTimeInterval<AutoCheckUpdate)
Return
If (AutoCheckOnceFlag=1)
Gosub, Label_GetLatestAppInfo
If (最新版本="v0.0.0"){
Return
}Else{
NewAppVersion := GetVersionComp(最新版本)
OldAppVersion := GetVersionComp(APPVersion)
If (NewAppVersion>OldAppVersion){
Gosub, Label_Update_LatestCheckDateTime
MsgBox, 52, %APPName%检查更新, 有新的版本可以更新,是否更新?`n`n最新版本:%最新版本%`n`n当前版本:v%APPVersion%
IfMsgBox Yes
Gosub, Label_Update_App
}
}
Return
Label_UpdateCheckDateTimeInterval: ; 更新检查更新间隔
CheckDateTimeInterval := A_Now
EnvSub, CheckDateTimeInterval, Format("{:014}", RegExReplace(LatestCheckDateTime, "(-|\s|:)")), days
Return
Label_Update_LatestCheckDateTime: ; 更新最后检查更新日期
FormatTime, LatestCheckDateTime , A_Now, yyyy-MM-dd HH:mm:ss
SetTimer, Label_AutoReload_MTime, off
IniWrite, %LatestCheckDateTime%, %INI%, 信息变量, 最近检查更新日期
Gosub, Label_Init_ResetINI
Return
Label_Update_App: ; 更新App
If (更新地址!=""){
DownloadFile(更新地址,"KBLAutoSwitch.ahk",KBLTempFilePath,ahk文件大小)
}Else{
MsgBox,16,,下载失败,请检查网络!
}
Return
Label_ClearMEM: ; 清理内存
pid:=() ? DllCall("GetCurrentProcessId") : pid
h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
DllCall("CloseHandle", "Int", h)
Return
;-----------------------------------【配置文件检测功能】-----------------------------------------------
Label_AutoReload_MTime: ; 定时重新加载脚本
RegRead, mtime_ini_path_reg, HKEY_CURRENT_USER, Software\KBLAutoSwitch, %INI%
FileGetTime, mtime_ini_path, %INI%, M ; 获取修改时间.
RegRead, SystemUsesLightTheme_new, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
if (mtime_ini_path_reg != mtime_ini_path || SystemUsesLightTheme_new != SystemUsesLightTheme){
gosub, Menu_Reload
}
SystemUsesLightTheme := SystemUsesLightTheme_new
Return
Label_Init_ResetINI: ; 配置文件更改后自动重新加载配置文件
FileGetTime, mtime_ini_path, %INI%, M ; 获取修改时间.
RegWrite, REG_SZ, HKEY_CURRENT_USER, SOFTWARE\KBLAutoSwitch, %INI%, %mtime_ini_path%
if (Auto_Reload_MTime>0)
SetTimer, Label_AutoReload_MTime, %Auto_Reload_MTime%
Return
;-----------------------------------【输入法自动切换功能】-----------------------------------------------
shellMessage(wParam, lParam) { ; 接受系统窗口回调消息切换输入法, 第一次是实时,第二次是保障
If ( wParam=1 || wParam=32772 || wParam=5 || wParam=4) {
shellMessageFlag := 1
SetTimer, Label_SetTimer_ResetshellMessageFlag,-500
Gosub, Label_Shell_KBLSwitch
If !WinActive("ahk_group NoTwiceSwitchAppList_ahk_group")
SetTimer, Label_Shell_KBLSwitch, -100
}Else If (wParam=56){
NextChangeFlag := 1
lastKBLCode56 := getIMEKBL(gl_Active_IMEwin_id)
LastKBLState56 := (lastKBLCode56!=EN_Code?(getIMECode(gl_Active_IMEwin_id)!=0?0:1):2)
}Else If (NextChangeFlag=1 && wParam=2){
NextChangeFlag := 0
KBLCode56 := getIMEKBL(gl_Active_IMEwin_id)
If (KBLCode56=CN_Code && KBLCode56=lastKBLCode56 && LastKBLState56!=2){
shellMessageFlag := 1
SetTimer, Label_SetTimer_ResetshellMessageFlag,-500
Gosub, Label_KBLSwitch_LastKBLState56
If !WinActive("ahk_group NoTwiceSwitchAppList_ahk_group")
SetTimer, Label_KBLSwitch_LastKBLState56, -100
}
Else If (KBLCode56=CN_Code && KBLCode56!=lastKBLCode56){
shellMessageFlag := 1
SetTimer, Label_SetTimer_ResetshellMessageFlag,-500
Gosub, Label_KBLSwitch_LastKBLState561
If !WinActive("ahk_group NoTwiceSwitchAppList_ahk_group")
SetTimer, Label_KBLSwitch_LastKBLState561, -100
}
lastKBLCode56 := KBLCode56
}
}
Label_KBLSwitch_LastKBLState561: ; 英文输入法切换到中文输入法时
If WinActive("ahk_group cn_ahk_group"){ ;切换中文输入法
setKBLlLayout(0,1)
}Else If WinActive("ahk_group cnen_ahk_group"){ ;切换英文(中文)输入法
setKBLlLayout(1,1)
}Else If WinActive("ahk_group cn_ahk_group_custom"){ ;窗口组切换中文输入法
setKBLlLayout(0,1)
}Else If WinActive("ahk_group cnen_ahk_group_custom"){ ;窗口组切换英文(中文)输入法
setKBLlLayout(1,1)
}
Return
Label_KBLSwitch_LastKBLState56: ; 中文输入法切换到中文输入法时
setKBLlLayout(LastKBLState56,1)
Return
Label_SetTimer_ResetshellMessageFlag: ; 定时重置未在接收切换消息
shellMessageFlag := 0
Return
Label_Shell_KBLSwitch: ; 根据激活窗口切换输入法
Critical On
If (SetTimer_Reset_KBL_Time>0 && WinActive("ahk_group SetTimer_Reset_KBL_WinGroup")) ; 无操作定时重置输入法
SetTimer, Label_SetTimer_ResetKBL, % SetTimer_Reset_KBL_Time*1000/60
Else If (SetTimer_Reset_KBL_Time>0)
SetTimer, Label_SetTimer_ResetKBL, Delete
If WinActive("ahk_group unswitch_ahk_group") ;不进行切换的屏蔽程序
Return
If WinActive("ahk_group DisableSwitchAppList_ahk_group"){ ;不进行切换的屏蔽程序
showSwitch()
}Else If WinActive("ahk_group unswitch_ahk_group_before"){ ;没必要切换的窗口前,保证切换显示逻辑的正确
setKBLlLayout(LastKBLState)
}Else If WinActive("ahk_group cn_ahk_group"){ ;切换中文输入法
setKBLlLayout(0,1)
}Else If WinActive("ahk_group cnen_ahk_group"){ ;切换英文(中文)输入法
setKBLlLayout(1,1)
}Else If WinActive("ahk_group en_ahk_group"){ ;切换英文输入法
setKBLlLayout(2,1)
}Else If WinActive("ahk_group cn_ahk_group_custom"){ ;窗口组切换中文输入法
setKBLlLayout(0,1)
}Else If WinActive("ahk_group cnen_ahk_group_custom"){ ;窗口组切换英文(中文)输入法
setKBLlLayout(1,1)
}Else If WinActive("ahk_group en_ahk_group_custom"){ ;窗口组切换英文输入法
setKBLlLayout(2,1)
}Else If WinActive("ahk_group unswitch_ahk_group_after"){ ;没必要切换的窗口后,保证切换显示逻辑的正确
setKBLlLayout(LastKBLState)
}Else {
setKBLlLayout(Real_Default_Keyboard-1,1)
}
Critical Off
Return
Label_SetTimer_ResetKBL: ; 定时重置输入法状态
If (A_TimeIdle>SetTimer_Reset_KBL_Time*1000){
SendInput, {F22 up}
gosub, Reset_KBL
}
Return
;-----------------------------------【输入法切换功能】-----------------------------------------------
setKBLlLayout(KBL:=0,Source:=0) { ; 设置输入法键盘布局
AutoSwitchFrequency += Source
gl_Active_IMEwin_id := getIMEwinid()
CapsLockState := LastCapsState
If !WinActive("ahk_group Inner_AHKGroup_NoCapsLock") { ; 设置大小写
Switch Reset_CapsLock_State
{
Case 1: SetCapsLockState, Off
Case 2: SetCapsLockState, On
}
If (Reset_CapsLock_State>0)
CapsLockState := Reset_CapsLock_State-1
}
LastKBLCode := getIMEKBL(gl_Active_IMEwin_id)
If (KBL=0){ ; 切换中文输入法
If (LastKBLCode=CN_Code){
setIME(1,gl_Active_IMEwin_id)
}Else{
SendMessage, 0x50, , %CN_Code%, , ahk_id %gl_Active_IMEwin_id%,,,,1000
Sleep,50
setIME(1,gl_Active_IMEwin_id)
}
}Else If (KBL=1){ ; 切换英文(中文)输入法
If (LastKBLCode=CN_Code){
setIME(0,gl_Active_IMEwin_id)
}Else{
SendMessage, 0x50, , %CN_Code%, , ahk_id %gl_Active_IMEwin_id%,,,,1000
Sleep,50
setIME(0,gl_Active_IMEwin_id)
}
}Else If (KBL=2){ ; 切换英文输入法
If (LastKBLCode!=EN_Code)
PostMessage, 0x50, , %EN_Code%, , ahk_id %gl_Active_IMEwin_id%
}
try showSwitch(KBL,CapsLockState,1)
SetTimer, Label_Change_TrayTip, -1000
}
setIME(setSts, win_id:="") { ; 设置输入法状态-获取状态-末位设置
SendMessage 0x283, 0x001, 0, , ahk_id %win_id%,,,,1000
CONVERSIONMODE := 2046&ErrorLevel, CONVERSIONMODE += setSts
SendMessage 0x283, 0x002, CONVERSIONMODE, , ahk_id %win_id%,,,,1000
SendMessage 0x283, 0x006, setSts, , ahk_id %win_id%,,,,1000
Return ErrorLevel
}
getIMEwinid() { ; 获取激活窗口IME线程id
If WinActive("ahk_class ConsoleWindowClass"){
WinGet, win_id, , ahk_exe conhost.exe
}Else If WinActive("ahk_group focus_control_ahk_group"){
ControlGetFocus, CClassNN, A
If (CClassNN = "")
WinGet, win_id, , A
Else
ControlGet, win_id, Hwnd, , %CClassNN%
}Else
WinGet, win_id, , A
IMEwin_id := DllCall(ImmGetDefaultIMEWnd, Uint, win_id, Uint)
Return IMEwin_id
}
getIMEKBL(win_id:="") { ; 获取激活窗口键盘布局
thread_id := DllCall("GetWindowThreadProcessId", "UInt", win_id, "UInt", 0)
IME_State := DllCall("GetKeyboardLayout", "UInt", thread_id)
Switch IME_State
{
Case 134481924:Return 2052
Case 67699721:Return 1033
Default:Return IME_State
}
}
getIMECode(win_id:="") { ; 获取激活窗口键盘布局中英文状态
SendMessage 0x283, 0x005, 0, , ahk_id %win_id%,,,,1000
IME_Input_State := ErrorLevel
If (IME_Input_State=1){
SendMessage 0x283, 0x001, 0, , ahk_id %win_id%,,,,1000
IME_Input_State := 1&ErrorLevel
}
Return IME_Input_State
}
;-----------------------------------【状态提示功能】-----------------------------------------------
showSwitch(KBLState:="",CapsLockState:="",ForceShowSwitch:=0) { ; 显示中英文状态(托盘图标、鼠标光标、Gui、TT)
If (KBLState=""){
gl_Active_IMEwin_id := getIMEwinid()
LastKBLCode := getIMEKBL(gl_Active_IMEwin_id)
KBLState := (LastKBLCode!=EN_Code?(getIMECode(gl_Active_IMEwin_id)!=0?0:1):2)
}
WinGetClass, class, A
If (class="" || class="ForegroundStaging") ; alt+tab出现的ahk_class
KBLState := LastKBLState
If (CapsLockState="")
CapsLockState := DllCall("GetKeyState", UInt, 20) & 1
If (Cur_Size)
MonitorNum := 1
Else{
CoordMode, Mouse , Screen
MouseGetPos, OutputVarX, OutputVarY
MonitorNum := getMonitorNum(OutputVarX,OutputVarY)
}
Display_KBL_Flag := Object()
If (ForceShowSwitch=0 && LastKBLState=KBLState && LastCapsState=CapsLockState && LastMonitorNum=MonitorNum)
Return
If (ForceShowSwitch!=0 || LastKBLState!=KBLState || LastCapsState!=CapsLockState){
LastKBLState:=KBLState
LastCapsState:=CapsLockState
If (Display_KBL_Flag[1]!=1){
Display_KBL_Flag[1]:=1
TT_Display_KBL(KBLState,LastCapsState)
}
If (Display_KBL_Flag[2]!=1){
Display_KBL_Flag[2]:=1
Tray_Display_KBL(KBLState,CapsLockState)
}
If (Display_KBL_Flag[3]!=1){
Display_KBL_Flag[3]:=1
Cur_Display_KBL(KBLState,CapsLockState,MonitorNum)
}
}
If (ForceShowSwitch!=0 && LastMonitorNum!=MonitorNum){
LastMonitorNum := MonitorNum
static LastMonitorW:=0
If (Display_KBL_Flag[3]!=1 && LastMonitorW!=MonitorAreaObjects[MonitorNum][5]){
Display_KBL_Flag[3]:=1
LastMonitorW := MonitorAreaObjects[MonitorNum][5]
Cur_Display_KBL(KBLState,CapsLockState,MonitorNum)
}
}
}
Label_Init_ShowKBLGui: ; 创建输入法状态GUI
If (TT_OnOff_Style!=0){
TT_Transparency := StrReplace(TT_Transparency, ",", ",")
TT_Transparency_Input := StrSplit(TT_Transparency, ",")[1]
TT_Transparency_Fix := StrSplit(TT_Transparency, ",")[2]
TT_Transparency_Fix := TT_Transparency_Fix=""?TT_Transparency_Input:TT_Transparency_Fix
TT_Font_Size := StrReplace(TT_Font_Size, ",", ",")
TT_Font_Size_Input := StrSplit(TT_Font_Size, ",")[1]
TT_Font_Size_Fix := StrSplit(TT_Font_Size, ",")[2]
TT_Font_Size_Fix := TT_Font_Size_Fix=""?TT_Font_Size_Input:TT_Font_Size_Fix
TT_Shift := StrReplace(TT_Shift, ",", ",")
TT_Shift_X := StrSplit(TT_Shift, ",")[1]
TT_Shift_Y := StrSplit(TT_Shift, ",")[2]
TT_Shift_X := TT_Shift_X=""?0:TT_Shift_X,TT_Shift_Y := TT_Shift_Y=""?0:TT_Shift_Y
TT_Pos_Coef := StrReplace(TT_Pos_Coef, ",", ",")
global TT_Pos_Coef_X := StrSplit(TT_Pos_Coef, ",")[1]
global TT_Pos_Coef_Y := StrSplit(TT_Pos_Coef, ",")[2]
TT_Pos_Coef_X := TT_Pos_Coef_X=""?0:TT_Pos_Coef_X,TT_Pos_Coef_Y := TT_Pos_Coef_Y=""?0:TT_Pos_Coef_Y
If (TT_OnOff_Style!=3){
Gui, SwitchTT:Destroy
Gui, SwitchTT:-SysMenu +ToolWindow +AlwaysOnTop -Caption -DPIScale +HwndSwitchTT_id +E0x20
Gui, SwitchTT:Color, %GuiTTBackCnColor%
Gui, SwitchTT:Font, c%GuiTTCnColor% s%TT_Font_Size_Input%, %FontType%
Gui, SwitchTT:Add,Text, x18 y3 HwndTT_Edit_Hwnd Center, %Display_En%
ControlGetPos, , , Text_W, Text_H, , ahk_id %TT_Edit_Hwnd%
global TT_W := Text_W+18
global TT_H := Text_H+8
WinSet, Transparent,%TT_Transparency_Input%, ahk_id %SwitchTT_id%
WinSet, Region, 10-0 W%TT_W% H%TT_H% R5-5, ahk_id %SwitchTT_id%
global TT_Shift_X_Real:=TT_Shift_X-TT_W-12
global TT_Shift_Y_Real:=TT_Shift_Y-2-TT_H
}
If (TT_OnOff_Style=3 || TT_OnOff_Style=4){
Gui, SwitchTT1:Destroy
Gui, SwitchTT1:-SysMenu +ToolWindow +AlwaysOnTop -Caption -DPIScale +HwndSwitchTT_id1 +E0x20
Gui, SwitchTT1:Color, %GuiTTBackCnColor%
Gui, SwitchTT1:Font, c%GuiTTCnColor% s%TT_Font_Size_Fix%, %FontType%
Gui, SwitchTT1:Add,Text, x18 y3 HwndTT_Edit_Hwnd1 Center, %Display_En%
ControlGetPos, , , Text_W, Text_H, , ahk_id %TT_Edit_Hwnd1%
global TT_W1 := Text_W+18
global TT_H1 := Text_H+8
WinSet, Transparent,%TT_Transparency_Fix%, ahk_id %SwitchTT_id1%
WinSet, Region, 10-0 W%TT_W1% H%TT_H1% R5-5, ahk_id %SwitchTT_id1%
}
}
Return
TT_Display_KBL(KBLState,CapsLockState) { ; 显示输入法状态-TT方式
If (TT_OnOff_Style=0 || WinExist("ahk_class #32768") || WinActive("ahk_group DisableTTShowAppList_ahk_group")){
Gosub, Label_Hide_All
Return
}
KBLMsg := CapsLockState!=0?"A":KBLState=0?Display_Cn:KBLState=1?Display_CnEn:Display_En
TT_Shift_flag := 0
If (TT_OnOff_Style=1){
MouseGetPos, CaretX, CaretY
}Else{
If (TT_OnOff_Style=3){
Caret := getDisplayPos(TT_Pos_Coef_X,TT_Pos_Coef_Y,TT_W1,TT_H1)
CaretX := Caret["x"],CaretY := Caret["y"]
TT_Shift_flag := 1
}Else{
GetCaret(CaretX, CaretY)
If (TT_OnOff_Style=2 && A_Cursor="IBeam" && CaretX=0 && CaretY=0)
MouseGetPos, CaretX, CaretY
Else If (TT_OnOff_Style=4 && CaretX=0 && CaretY=0){
Caret := getDisplayPos(TT_Pos_Coef_X,TT_Pos_Coef_Y,TT_W1,TT_H1)
CaretX := Caret["x"],CaretY := Caret["y"]
TT_Shift_flag := 1
}
}
}
If (TT_Shift_flag=0){
Gui, SwitchTT1:Hide
Gosub, Label_Change_SwitchTT
CaretX := CaretX+TT_Shift_X_Real, CaretY := CaretY+TT_Shift_Y_Real
try Gui, SwitchTT:Show, x%CaretX% y%CaretY% NoActivate
}Else{
Gui, SwitchTT:Hide
Gosub, Label_Change_SwitchTT