-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnRu.ahk
170 lines (151 loc) · 5.12 KB
/
EnRu.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
/*
git clone https://github.com/abakum/EnRu.git
Another global keyboard layout switcher by clicking the left or right Ctrl key<br>
Еще один глобальный переключатель раскладки клавиатуры щелчком левой или правой клавиши Ctrl
- Press and release the left `Ctrl` key to switch the keyboard layout to `en_US`.<br>
Нажми и отпусти левую клавишу `Ctrl` чтоб переключить раскладку клавиатуры на `en_US.`
- Press and release the right `Ctrl` key to switch the keyboard layout to `ru_Ru`, but if the [UltraVNC\vncviewer](https://uvnc.com/docs/uvnc-viewer/71-viewer-gui.html) window is active, the local keyboard layout will be `en_US`.<br>
Нажми и отпусти правую клавишу `Ctrl` чтоб переключить раскладку клавиатуры на `ru_Ru`, но если активно окно с [UltraVNC\vncviewer](https://uvnc.com/docs/uvnc-viewer/71-viewer-gui.html) то раскладка локальной клавиатуры будет `en_US`
git push origin --tags
*/
;@Ahk2Exe-Let ProductVersion=v0.6.4-lw
#Requires AutoHotkey v2.0
#SingleInstance
;@Ahk2Exe-SetMainIcon 0.ico
;@Ahk2Exe-AddResource 1.ico, 160
;@Ahk2Exe-AddResource 2.ico, 161
;@Ahk2Exe-SetName EnRu
;@Ahk2Exe-SetCopyright Abakum
;@Ahk2Exe-SetProductVersion %U_ProductVersion%
;@Ahk2Exe-SetDescription Changing the input language by clicking the left or right `Ctrl`
; @Ahk2Exe-SetLanguage 0x0419
; @Ahk2Exe-SetDescription Смена языка ввода по клику левого или правого `Ctrl`
;@Ahk2Exe-PostExec "%A_ComSpec%" /c "cd /d %A_ScriptDir%&git tag %U_ProductVersion%"
;@Ahk2Exe-Cont , , , , 1
;https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-inputlangchangerequest
WM_INPUTLANGCHANGEREQUEST:=0x0050
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindow
GW_HWNDPREV:=3
;"c:\Program Files\uvnc bvba\UltraVNC\vncviewer.exe"
uvnc:="VNCMDI_Window"
Frequency:=523
Period:=2 ;set negative to stop polling
lastHKL:=0
EnRu:=[] ;["us","ru"]
KLID:=[] ;["00000409", "00000419"]
HKL:=[] ;[0x04090409, 0x04190419]
Loop Reg, "HKCU\Keyboard Layout\Preload"{
KLID.Push RegRead("HKCU\Keyboard Layout\Preload", A_Index)
EnRu.Push RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes" , KLID[A_Index])
HKL.Push DllCall("LoadKeyboardLayout", "Str", KLID[A_Index], "UInt", 0)
}
TrayIcon
SetTimer () => TrayIcon(), Abs(Period)*1000
~LControl up::{
if "LControl"=A_PriorKey
Lang 1
}
~RControl up::{
if "RControl"=A_PriorKey
Lang 2
}
A_TrayMenu.Insert "1&"
A_TrayMenu.Insert "1&", EnRu[2], Item
A_TrayMenu.Insert "1&", EnRu[1], Item
;switch lang by index ItemPos
Lang(ItemPos){
Item EnRu[ItemPos], ItemPos, A_TrayMenu
}
;switch lang by menu
;set lastHKL as HKL[ItemPos]
Item(ItemName, ItemPos, MyMenu) {
hwnd:=DllCall("GetForegroundWindow", "Ptr")
if hwnd=0
return
class:=WinGetClass(hwnd)
if class==uvnc{
SoundBeep Frequency*ItemPos
ItemPos:=1
}
else
ToolTip ItemName
loop{
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-postmessagea
try{
PostMessage WM_INPUTLANGCHANGEREQUEST, , HKL[ItemPos], , hwnd
sleep 7
; SendMessage WM_INPUTLANGCHANGEREQUEST, , HKL[ItemPos], , hwnd
} catch {
ToolTip "PostMessage WM_INPUTLANGCHANGEREQUEST, , " HKL[ItemPos] ", , " hwnd
}
if GetKeyboardLayout()=HKL[ItemPos]{
global lastHKL:=HKL[ItemPos]
icon ItemPos
return
}
hwnd:=DllCall("GetWindow", "Ptr", hwnd, "UInt", GW_HWNDPREV, "Ptr")
if hwnd=0
return
if class=="Shell_TrayWnd"{
DllCall("SetForegroundWindow", "Ptr", hwnd)
class:=WinGetClass(hwnd)
}
}
}
;get lang as HKL
GetKeyboardLayout() {
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow
hwnd:=DllCall("GetForegroundWindow", "Ptr")
if hwnd && WinGetClass(hwnd)=="ConsoleWindowClass"
hwnd:=DllCall("GetWindow", "Ptr", hwnd, "UInt", GW_HWNDPREV, "Ptr")
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid
if hwnd=0
tid:=0
else
tid:=DllCall("GetWindowThreadProcessId", "Ptr", hwnd, "Ptr", 0, "Ptr")
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeyboardlayout
return DllCall("GetKeyboardLayout", "UInt", tid, "UInt")
}
;change icon in tray by ItemPos
icon(ItemPos){
if ItemPos=0
A_IconTip:=""
else{
A_IconTip:=EnRu[ItemPos]
if !WinActive("ahk_class " uvnc)
SoundBeep Frequency*ItemPos
}
;@Ahk2Exe-IgnoreBegin
TraySetIcon ItemPos ".ico"
;@Ahk2Exe-IgnoreEnd
/*@Ahk2Exe-Keep
TraySetIcon A_ScriptName, -(159+ItemPos)
*/
}
;hide ToolTip
;change lang to US in window of UltraVNC-viewer
;change icon in tray accordingly GetKeyboardLayout
;set lastHKL as GetKeyboardLayout
TrayIcon(){
ToolTip
if Period<0 && lastHKL>0{
if lastHKL!=HKL[1] && WinActive("ahk_class " uvnc)
Lang 1
return
}
curHKL:=GetKeyboardLayout()
if curHKL!=HKL[1] && WinActive("ahk_class " uvnc){
Lang 1
return
}
if lastHKL=curHKL
return
global lastHKL:=curHKL
For i, v in HKL{
if v=curHKL{
icon i
return
}
}
icon 0
}