根据程序配置输入法V1.1505

;--------------------------------------V1.1505
;~ 修改排除配置文件的模式
;~ 修改功能为托盘图标
;~ 修改窗口样式为透明
;~ 修改可检测隐藏窗口如QQ
;~ 修改添加模式更直观
;~ 修改保存时出现的重复现象
;~ 修改一些笨方法的判断方式
;~ 解决魔兽开启时获取不到列表
;~ 解决部分版本保存配置出错
;--------------------------------------需要先配置
#Persistent
#SingleInstance force
DetectHiddenWindows,off
HKLnum:=DllCall("GetKeyboardLayoutList","uint",0,"uint",0)
VarSetCapacity( HKLlist, HKLnum*4, 0 )
DllCall("GetKeyboardLayoutList","uint",HKLnum,"uint",&HKLlist)
Loop,%HKLnum%
{
    SetFormat, integer, hex
    HKL:=NumGet( HKLlist,(A_Index-1)*4 )
    StringTrimLeft,Layout,HKL,2
    Layout:= Layout=8040804 ? "00000804" : Layout
    Layout:= Layout=4090409 ? "00000409" : Layout
    RegRead,IMEName,HKEY_LOCAL_MACHINE,SYSTEMCurrentControlSetControlKeyboard Layouts%Layout%,Layout Text
    RegRead,Tubiao,HKEY_LOCAL_MACHINE,SYSTEMCurrentControlSetControlKeyboard Layouts%Layout%,Ime File
    SetFormat, integer, D
    if IMEName
    {
        编号列 = %IMEName%`r%Layout%`n%编号列%
		输入法 = %IMEName%|%输入法%
    }
}
Hotkey, Enter ,Ente
Hotkey, Enter ,off
;--------------------------------------Menu界面
Menu, Tray, Tip, By,小死猛
Menu, Tray, Add, By,小死猛, Menu_显示窗口
Menu, Tray, Add, 联系作者, Menu_联系作者
Menu, Tray, Add, 支持作者, Menu_支持作者
Menu, Tray, Add,
Menu, Tray, Add, 开启脚本, Menu_开启脚本
Menu, Tray, Add, 回车切换, Menu_回车切换
Menu, Tray, Add, 开机启动, Menu_开机启动
Menu, Tray, Add,
Menu, Tray, Add, 重启脚本, Menu_重启脚本
Menu, Tray, Add, 退出脚本, Menu_退出脚本
Menu, Tray, Default, By,小死猛
Menu, tray, NoStandard
;--------------------------------------Gui界面
Gui,+LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Add, GroupBox, xm ym vBian w360 h165 cfff100,单击列表项配置输入法
Gui, Add, ListView, Checked -Hdr Multi Report AltSubmit  r7 x20 y22 w340 gMyListView vMyListView,进程ID|输入状态|中英|编号|路径
Gui, Add,DropDownList,AltSubmit x20 y145 w120 vColorChoice gColorChoice Choose1,%输入法%
Gui, Add,Button,x+10 h20 vqiehuan gqiehuan, Shift切换
Gui, Add,Button,x+10 h20 gYin vYin, 隐藏可视
Gui, Add,Button,x+10 h20 gbao, 刷新保存
Gui,Color, 00a99d
GuiControl +Backgrounddbdbdb, MyListView
Gui +HwndMyGuiHwnd
;--------------------------------------出现界面后需要执行
GuiStart()
IfExist ,%A_Startup%输入法.lnk
{
    TrayTip,,脚本已自动启动, 10, 1
    Menu, tray, rename, 开机启动, 关闭自启
    gosub,Menu_开启脚本
}
return
;--------------------------------------Menu命令一
Menu_显示窗口:
    IfWinExist, ahk_class Shell_TrayWnd
    {
    CoordMode,Mouse,Screen
    MouseGetPos, OutputVarX, OutputVarY,
    WinGetPos , X, Y, Width, Height, ahk_class Shell_TrayWnd
    }
    else
    {
    Gui,Show,AutoSize
    GuiControl, Disable,qiehuan
    GuiControl,,bian,单击列表项配置输入法
    名称 =
    return
    }
    if (Width > Height)
    {
        if not Y
        { ;底部
            OutputVarX := OutputVarX - 387
            OutputVarY := Height
        }
        else
        { ;顶部
            OutputVarX := OutputVarX - 387
            OutputVarY := Y-176
        }
    }
    else
    {
        if not X
        { ;左部
            OutputVarX := Width
            OutputVarY := OutputVarY-176
        }
        else
        { ;右部
            OutputVarX := X -387
            OutputVarY := OutputVarY-176
        }
    }
    IfWinExist, ahk_id %MyGuiHwnd%
    {
        Gui,Cancel
        return
    }
    Gui,Show,AutoSize x%OutputVarX% y%OutputVarY%
    GuiControl, Disable,qiehuan
    GuiControl,,bian,单击列表项配置输入法
    名称 =
return
Menu_联系作者:
    Run tencent://message/?uin=4845514
return
Menu_支持作者:
    SetTimer,ChangeButtonNames,50
    MsgBox,4,感谢支持本功能,感谢支持本功能`n小时候答应姐姐,她要老了牙口不好。`n给他换一口陶瓷牙,还剩22颗牙没换求赞助。
    IfMsgBox Yes
        MsgBox 支付宝帐号:skc2015@163.com`n户名:刘猛
return
ChangeButtonNames:
    IfWinNotExist,感谢支持本功能
        return
    SetTimer,ChangeButtonNames,off
    WinActivate
    ControlSetText,Button1,获取账号
    ControlSetText,Button2,残忍拒绝
return
;--------------------------------------Menu命令二段
Menu_开启脚本:
winuu = 5
    if NewName  关闭脚本
    {
        winoo = 6
        OldName = 开启脚本
        NewName = 关闭脚本
    }
    else
    {
        winoo = 4
        OldName = 关闭脚本
        NewName = 开启脚本
    }
    Menu, tray, rename, %OldName%, %NewName%
    gosub,kik
return
Menu_回车切换:
    Hotkey, Enter,Toggle
    if neww  关闭回车
    {
        name = 回车切换
        neww = 关闭回车
    }
    else
    {
        name = 关闭回车
        neww = 回车切换
    }
    Menu, tray, rename, %name%, %neww%
return
Menu_开机启动:
    IfExist ,%A_Startup%输入法.lnk
    {
        Menu, tray, rename, 关闭自启, 开机启动
        FileDelete,%A_Startup%输入法.lnk
    }
    else
    {
        Menu, tray, rename, 开机启动, 关闭自启
        FileCreateShortcut,%A_ScriptDir%%A_ScriptName%,%A_Startup%输入法.lnk
    }
return
;--------------------------------------Menu命令三段
Menu_重启脚本:
    Reload
Menu_退出脚本:
    ExitApp
;--------------------------------------主要功能
kik:
while winoo>winuu
{
WinGet, win_pc,ID,A ;避免QQ聊天窗口与界面窗口同在问题
WinWaitNotActive,ahk_id %win_pc% ;只在出现新窗口时执行优化效率 同样也避免了与保存的冲突
WinGet, win_pp,ProcessName,A
Loop % LV_GetCount()
    {
        RowNumber := LV_GetNext(RowNumber,"Checked")
        if not RowNumber
            break
        LV_GetText(进程, RowNumber, 1)
        IfInString,win_pp, %进程%
        {
            LV_GetText(Layout, RowNumber, 4)
            SwitchIME(Layout)
            LV_GetText(shi, RowNumber, 3)
            if shi = Shift
            {
                Send {Shift}
            }
        break
        }
    }
}
return
Ente:
    WinGet, win_cl, ProcessName, A
    Loop % LV_GetCount()
    {
        RowNumber := LV_GetNext(RowNumber,"Checked")
        if not RowNumber
            continue
        LV_GetText(进程, RowNumber, 1)
        IfInString,win_cl, %进程%
        {
            LV_GetText(Layout, RowNumber, 4)
            SwitchIME(Layout)
            Send {Enter}
            LV_GetText(shi, RowNumber, 3)
            if shi = Shift
            {
                Send {Shift}
            }
            return
        }
    }
    Send {Enter}
return
;--------------------------------------单击控件
MyListView:
    if A_GuiEvent = Normal
    {
        win_xz := A_EventInfo
        if not win_xz
        {  ;避免点击列表中空白部分
            TrayTip,空白,请勿点击列表中空白部分, 10, 2
            return
        }
        LV_GetText(dier, win_xz, 2)
        if not dier
        {  ;判断2列是否含有信息 决定禁用或启用切换按钮
            GuiControl, Disable,qiehuan
        }
        else
        {
            GuiControl, Enable ,qiehuan
        }
        LV_GetText(disan, win_xz, 3)
        if not disan
        {  ;判断3列是否含有信息 决定更换按钮内容
            GuiControl,,qiehuan,Shift切换
            win_shi =Shift
        }
        else
        {
            GuiControl,,qiehuan,取消切换
            win_shi =
        }
        LV_GetText(名称, win_xz,1 ) ;更新外框信息
        GuiControl,,bian,为"%名称%"选择输入法
    }
return
;--------------------------------------GUI控件项目
ColorChoice:
    if not 名称
    {
        TrayTip,未选择,请在列表中选择程序, 10, 1
        return
    }
    Gui, Submit,NoHide
    Loop, parse, 编号列, `n
    {
    if A_Index = %ColorChoice%
    {
    win_sw = %A_LoopField%
    break
    }
    }
    Loop, parse, win_sw, `r
    {
    if A_Index = 1
    {
    LV_Modify(win_xz,,,A_LoopField)
    }
    if A_Index = 2
    {
    LV_Modify(win_xz,,,,,A_LoopField)
    }
    }
    LV_Modify(win_xz,"Check")
    GuiControl, Enable ,qiehuan
return
qiehuan:
    if not 名称
    {
        TrayTip,未选择,请在列表中选择程序, 10, 1
        return
    }
    LV_GetText(dier, win_xz, 2)
    if not dier
    {
        TrayTip,未选择,清先配置%名称%输入法, 10, 1
        return
    }
    LV_GetText(disan, win_xz, 3)
    if not disan
    {
        GuiControl,,qiehuan,取消切换
        win_shi =Shift
    }
    else
    {
        GuiControl,,qiehuan,Shift切换
        win_shi =
    }
    LV_Modify(win_xz,,,,win_shi)
    LV_Modify(win_xz,"Check")
return
Yin:
win_ck = 1
gosub,bao
DetectHiddenWindows,off
win_ck =
Return
bao:
    GuiControl, Disable ,bao
    FileSetAttrib, -R, %A_ScriptDir%输入法设定.ini ;取消配置文件只读选项
    FileDelete,%A_ScriptDir%输入法设定.ini
    Loop % LV_GetCount()
    {
        RowNumber := LV_GetNext(RowNumber,"Checked")
        if not RowNumber
            break
        LV_GetText(进程, RowNumber, 1)
        LV_GetText(状态, RowNumber, 2)
        LV_GetText(中英, RowNumber, 3)
        LV_GetText(编号, RowNumber, 4)
        LV_GetText(路径, RowNumber, 5)
        IniWrite, %进程%, %A_ScriptDir%输入法设定.ini, 选定项目,%A_Index%
        IniWrite, %进程%, %A_ScriptDir%输入法设定.ini, %进程%, 进程
        IniWrite, %状态%, %A_ScriptDir%输入法设定.ini, %进程%, 状态
        IniWrite, %中英%, %A_ScriptDir%输入法设定.ini, %进程%, 中英
        IniWrite, %编号%, %A_ScriptDir%输入法设定.ini, %进程%, 编号
        IniWrite, %路径%, %A_ScriptDir%输入法设定.ini, %进程%, 路径
    }
    if win_ck = 1
    {
    DetectHiddenWindows,On
    }
    GuiStart()
    TrayTip,保存成功,如未刷新出隐藏至托盘的程序`n请开启隐藏可视, 10, 1
    GuiControl, Enable ,bao
return
;--------------------------------------加载列表
GuiStart() {
    LV_Delete()
    WinGet,WinList,List
    WinAll:= Object()
    ImageListID := IL_Create(WinAll)
    LV_SetImageList(ImageListID)
    WinListPN:=
    Loop,%WinList% {
        id:=WinList%A_Index%
        WinGet,win_ll,ProcessName,ahk_id %id%
        WinListPN:=WinListPN win_ll "`n"
    }
    Sort,WinListPN,U ;排除类似IE 或文本文件编辑
    Loop
    { ;排除配置文件中的项目
        IniRead, 排除, %A_ScriptDir%输入法设定.ini, 选定项目,%A_Index%,%A_Space%
        if not 排除
        {
            break
        }
        StringReplace, WinListPN, WinListPN, %排除% ,UseErrorLevel ,
    }
    Sort,WinListPN,U ;继续避免重复
    WinList_Array:=StrSplit(RTrim(WinListPN,"`n"),"`n")
    win_A_Index = 1
    For index, 进程 in WinList_Array {
        WinGet,路径,ProcessPath,ahk_exe %进程%
    IfNotExist ,%路径%
    { ;路径不存在则不添加
        continue
    }
    if (GetIconCount(路径)>0)
        IL_Add(ImageListID, 路径,1)
    else ;图标为空则不添加
        continue
    LV_Add("Icon" . win_A_Index,进程,,,,路径)
    win_A_Index++
}
RowNumber := LV_GetCount()
Loop
{ ;添加配置文件中项目
    IniRead, win_dq, %A_ScriptDir%输入法设定.ini, 选定项目,%A_Index%,%A_Space%
    if not win_dq
    {
        break
    }
    IniRead, 进程, %A_ScriptDir%输入法设定.ini, %win_dq%, 进程,%A_Space%
    IniRead, 状态, %A_ScriptDir%输入法设定.ini, %win_dq%, 状态,%A_Space%
    IniRead, 中英, %A_ScriptDir%输入法设定.ini, %win_dq%, 中英,%A_Space%
    IniRead, 编号, %A_ScriptDir%输入法设定.ini, %win_dq%, 编号,%A_Space%
    IniRead, 路径, %A_ScriptDir%输入法设定.ini, %win_dq%, 路径,%A_Space%%A_Space%
    IfNotExist ,%路径%
    {
        continue
    }
    RowNumber++
    IL_Add(ImageListID, 路径,1)
    LV_Add("Icon" . RowNumber,进程,状态,中英,编号,路径)
    LV_Modify(RowNumber,"Check")
}
LV_ModifyCol(1,110)
LV_ModifyCol(2,159)
LV_ModifyCol(3,50)
LV_ModifyCol(2,"SortDesc")
LV_ModifyCol(4,0)
LV_ModifyCol(5,0)
}
;--------------------------------------调用与获取
GetIconCount(file){ ;排除没有图标的程序
    Menu, test, add, test, handle
    Loop
    {
        try {
            id++
        Menu, test, Icon, test, % file, % id
    } catch error {
    break
}
}
return id-1
}
handle:
return
SwitchIME(dwLayout){ ;修改当前窗口输入法
    HKL:=DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1)
    ControlGetFocus,ctl,A
    SendMessage,0x50,0,HKL,%ctl%,A
}
;--------------------------------------脚本结束

给TA捐赠
共{{data.count}}人
人已捐赠
其他

根据程序配置输入法

2020-3-9 3:40:44

其他

格式化代码

2020-3-9 3:42:44

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索