SHOW:
|
|
- or go back to the newest paste.
| 1 | #NoEnv | |
| 2 | #SingleInstance force | |
| 3 | ||
| 4 | - | $~#Space::LangSwitch(1) |
| 4 | + | $~CapsLock::LangSwitch(1) |
| 5 | - | $~#Space up::LangSwitch(2) |
| 5 | + | $~CapsLock up::LangSwitch(2) |
| 6 | ||
| 7 | LangSwitch( iKeyDownUp=0 ) | |
| 8 | {
| |
| 9 | static tickLast | |
| 10 | IfEqual,iKeyDownUp,1 | |
| 11 | { tickLast=%A_TickCount%
| |
| 12 | return | |
| 13 | } | |
| 14 | IfEqual,iKeyDownUp,2 | |
| 15 | If( A_TickCount-tickLast>200 ) | |
| 16 | return | |
| 17 | ||
| 18 | HKL:=DllCall("GetKeyboardLayout", "uint",GetThreadOfWindow(), "uint")
| |
| 19 | ||
| 20 | HKLnum:=DllCall("GetKeyboardLayoutList","uint",0,"uint",0)
| |
| 21 | VarSetCapacity( HKLlist, HKLnum*4, 0 ) | |
| 22 | DllCall("GetKeyboardLayoutList","uint",HKLnum,"uint",&HKLlist)
| |
| 23 | loop,%HKLnum% | |
| 24 | { if( NumGet( HKLlist, (A_Index-1)*4 ) = HKL )
| |
| 25 | { HKL:=NumGet( HKLlist, mod(A_Index,HKLnum)*4 )
| |
| 26 | break | |
| 27 | } | |
| 28 | } | |
| 29 | ControlGetFocus,ctl,A | |
| 30 | SendMessage,0x50,0,HKL,%ctl%,A ;WM_INPUTLANGCHANGEREQUEST | |
| 31 | ||
| 32 | ;show traytip | |
| 33 | LOCALE_SENGLANGUAGE=0x1001 | |
| 34 | LOCALE_SENGCOUNTRY=0x1002 | |
| 35 | VarSetCapacity( sKbd, 260, 0 ) | |
| 36 | VarSetCapacity( sCountry, 260, 0 ) | |
| 37 | DllCall("GetLocaleInfo","uint",HKL>>16,"uint",LOCALE_SENGLANGUAGE, "str",sKbd, "uint",260)
| |
| 38 | DllCall("GetLocaleInfo","uint",HKL & 0xFFFF,"uint",LOCALE_SENGCOUNTRY, "str",sCountry, "uint",260)
| |
| 39 | traytip,%sKbd%,%sCountry% | |
| 40 | SetTimer,REMOVE_TOOLTIP,500 ;0.5 second | |
| 41 | return | |
| 42 | REMOVE_TOOLTIP: | |
| 43 | SetTimer,REMOVE_TOOLTIP,off | |
| 44 | traytip | |
| 45 | return | |
| 46 | } | |
| 47 | ||
| 48 | ;returns first thread for the <processID> | |
| 49 | ;sets optional <List> to pipe | separated thread list for the <processID> | |
| 50 | GetProcessThreadOrList( processID, byRef list="" ) | |
| 51 | {
| |
| 52 | ;THREADENTRY32 {
| |
| 53 | THREADENTRY32_dwSize=0 ; DWORD | |
| 54 | THREADENTRY32_cntUsage = 4 ;DWORD | |
| 55 | THREADENTRY32_th32ThreadID = 8 ;DWORD | |
| 56 | THREADENTRY32_th32OwnerProcessID = 12 ;DWORD | |
| 57 | THREADENTRY32_tpBasePri = 16 ;LONG | |
| 58 | THREADENTRY32_tpDeltaPri = 20 ;LONG | |
| 59 | THREADENTRY32_dwFlags = 24 ;DWORD | |
| 60 | THREADENTRY32_SIZEOF = 28 | |
| 61 | ||
| 62 | TH32CS_SNAPTHREAD=4 | |
| 63 | ||
| 64 | hProcessSnap := DllCall("CreateToolhelp32Snapshot","uint",TH32CS_SNAPTHREAD, "uint",0)
| |
| 65 | ifEqual,hProcessSnap,-1, return | |
| 66 | ||
| 67 | VarSetCapacity( thE, THREADENTRY32_SIZEOF, 0 ) | |
| 68 | NumPut( THREADENTRY32_SIZEOF, thE ) | |
| 69 | ||
| 70 | ret=-1 | |
| 71 | ||
| 72 | if( DllCall("Thread32First","uint",hProcessSnap, "uint",&thE ))
| |
| 73 | loop | |
| 74 | {
| |
| 75 | if( NumGet( thE ) >= THREADENTRY32_th32OwnerProcessID + 4) | |
| 76 | if( NumGet( thE, THREADENTRY32_th32OwnerProcessID ) = processID ) | |
| 77 | { th := NumGet( thE, THREADENTRY32_th32ThreadID )
| |
| 78 | IfEqual,ret,-1 | |
| 79 | ret:=th | |
| 80 | list .= th "|" | |
| 81 | } | |
| 82 | NumPut( THREADENTRY32_SIZEOF, thE ) | |
| 83 | if( DllCall("Thread32Next","uint",hProcessSnap, "uint",&thE )=0)
| |
| 84 | break | |
| 85 | } | |
| 86 | ||
| 87 | DllCall("CloseHandle","uint",hProcessSnap)
| |
| 88 | StringTrimRight,list,list,1 | |
| 89 | return ret | |
| 90 | } | |
| 91 | ||
| 92 | ; Returns thread owning specified window handle | |
| 93 | ; default = Active window | |
| 94 | GetThreadOfWindow( hWnd=0 ) | |
| 95 | {
| |
| 96 | IfEqual,hWnd,0 | |
| 97 | hWnd:=WinExist("A")
| |
| 98 | DllCall("GetWindowThreadProcessId", "uint",hWnd, "uintp",id)
| |
| 99 | GetProcessThreadOrList( id, threads ) | |
| 100 | IfEqual,threads, | |
| 101 | return 0 | |
| 102 | CB:=RegisterCallback("GetThreadOfWindowCallBack","Fast")
| |
| 103 | lRet=0 | |
| 104 | lParam:=hWnd | |
| 105 | loop,parse,threads,| | |
| 106 | { NumPut( hWnd, lParam )
| |
| 107 | DllCall("EnumThreadWindows", "uint",A_LoopField, "uint",CB, "uint",&lParam)
| |
| 108 | if( NumGet( lParam )=true ) | |
| 109 | { lRet:=A_LoopField
| |
| 110 | break | |
| 111 | } | |
| 112 | } | |
| 113 | DllCall("GlobalFree", "uint", CB)
| |
| 114 | return lRet | |
| 115 | } | |
| 116 | ||
| 117 | GetThreadOfWindowCallBack( hWnd, lParam ) | |
| 118 | {
| |
| 119 | IfNotEqual,hWnd,% NumGet( 0+lParam ) | |
| 120 | return true | |
| 121 | NumPut( true, 0+lParam ) | |
| 122 | return 0 | |
| 123 | } |