#Persistent #SingleInstance force #UseHook #InstallKeybdHook ;获取输入法 Array := Object() 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 Layout=%Layout% Array.Insert(Layout) } ;创建数据库 sDatabaseName = Habit.MDB sTableName := "Habit" adOpenStatic := 3, adLockOptimistic := 3, adUseClient := 3 AttributeString := FileExist(sDatabaseName) if not AttributeString { TrayTip,,正在创建数据库 oCatalog := ComObjCreate("ADOX.Catalog") oCatalog.Create("Provider='Microsoft.Jet.OLEDB.4.0';Data Source=" sDatabaseName) oTable := ComObjCreate("ADOX.Table") oTable.Name := sTableName oTable.Columns.Append("pid",202,50) for index, element in Array{ oTable.Columns.Append(element,202,50) } oTable.Columns.Append("Hotkeys",202,50) oTable.Columns.Append("number",202,50) oTable.Columns.Append("Route",202,200) oCatalog.Tables.Append(oTable) oTable := "" oCatalog := "" } oConnection := ComObjCreate("ADODB.Connection") sConnectionString := "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . sDatabaseName oConnection.Open(sConnectionString) ;启动脚本 Loop{ IfWinNotActive,ahk_exe %D_Name% { WinGet,D_Name,ProcessName,A if not D_Name continue gosub,D_cx sSearchCriteria = pid = '%D_Name%' oRecordset.Find(sSearchCriteria,,,1) if oRecordset.EOF{ oRecordset.AddNew() for index, element in Array { oRecordset.Fields[element]:="1" } WinGet,D_Route,ProcessPath,A oRecordset.Fields["pid"]:= D_Name oRecordset.Fields["Hotkeys"]:= "" oRecordset.Fields["number"]:= "" oRecordset.Fields["Route"]:= D_Route oRecordset.Update() }else{ D_Big= D_Value= for index, element in Array { A_element:=oRecordset.Fields[element].Value if (A_element>D_Big){ D_Big=%A_element% D_Value=%element% } } TrayTip,,%D_Name%`n配置:%D_Value%-%D_Big% SwitchIME(D_Value) } X_Name= } if A_TimeIdlePhysicalD_Name) { SetFormat,integer,hex HKL:=DllCall("GetKeyboardLayout","int",GetThRead(),UInt) StringTrimLeft,Layout,HKL,2 Layout:= HKL=0x8040804 ? "00000804" : Layout Layout:= HKL=0x4090409 ? "00000409" : Layout SetFormat,IntegerFast,d ;----------------------------- gosub,D_cx D_SS = pid = '%D_Name%' oRecordset.Find(D_SS,,,1) A_Layout:=oRecordset.Fields[Layout].Value J_Layout:=A_Layout+1 TrayTip,,%D_Name%`n写入:%Layout%-%J_Layout%`n%A_PriorKey% oRecordset.Fields[Layout]:= J_Layout oRecordset.MoveNext() X_Name=%D_Name% } Sleep, 100 } return /*输入测试 */ ;调用函数 GetThread(){ ;获取当前窗口输入法 ResultID:=0 hWnd:=WinExist("A") VarSetCapacity( thE, 28, 0 ) NumPut( 28, thE ) WinGet,processID,pid,ahk_id %hWnd% hProcessSnap := DllCall("CreateToolhelp32Snapshot","uint",4, "uint",processID) If (DllCall("Thread32First","uint",hProcessSnap, "uint",&thE )=0) Return 0 Loop{ If (NumGet(thE,12) = processID){ DllCall("CloseHandle","uint",hProcessSnap) ResultID:=NumGet(thE,8) Return ResultID } NumPut( 28, thE ) if( DllCall("Thread32Next","uint",hProcessSnap, "uint",&thE )=0){ DllCall("CloseHandle","uint",hProcessSnap) Return 0 } } } SwitchIME(dwLayout){ ;修改当前窗口输入法 HKL:=DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1) ControlGetFocus,ctl,A SendMessage,0x50,0,HKL,%ctl%,A } D_CX: ;查询数据库 oRecordset := ComObjCreate("ADODB.Recordset") oRecordset.CursorLocation := adUseClient oRecordset.Open("SELECT * FROM Habit ORDER BY pid DESC, Hotkeys DESC", oConnection, adOpenStatic, adLockOptimistic) return