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
#Persistent
#SingleInstance force

hasSwitched := 0

SetTitleMatchMode, 2
SetTimer, CheckSWWindow, 500

CheckSWWindow:
{
    IfWinActive, ahk_exe sldworks.exe
    {
        If (hasSwitched = 0)
        {
            ; 切换输入法为英文
            SendInput, {LAlt Down}{Shift Down}{Shift Up}{LAlt Up}
            hasSwitched := 1
        }
    }
    else
    {
        If (hasSwitched = 1)
        {
            ; 切换输入法为默认输入法
            SendInput, {LAlt Down}{Shift Down}{Shift Up}{LAlt Up}
            hasSwitched := 0
        }
    }
    return
}

ExitApp

这个修改后的脚本在切换出 SolidWorks 窗口时,会自动将输入法切换回默认输入法。当焦点离开 SolidWorks 窗口时,脚本会检查 hasSwitched 的值,如果为 1,则触发输入法切换回默认输入法,并将 hasSwitched 的值设置为 0。

.gif

Licensed under CC BY-NC-SA 4.0