Hangul/English toggle with right Alt key Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Hangul/English toggle with right Alt key  Topic is solved

15 Aug 2018, 02:51

I am trying to write a simple code to toggle between Hangul/English in Korean Microsoft IME.
Normally to toggle this I just press the right Alt key. However, when I write a code as below nothing happens. Can anyone help me out?

Code: Select all

Send, {RAlt Down}{RAlt Up}
Image
Attachments
hangulenglish.PNG
hangulenglish.PNG (56.25 KiB) Viewed 995 times
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 07:08

pro100andrik94 wrote:Maybe try

Code: Select all

Sendinput, {RAlt}
Still nothing happens...
pro100andrik94
Posts: 26
Joined: 08 Aug 2018, 07:27

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 07:38

Code: Select all

sendinput, {vk15}
Than this must work
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 07:44

wow, it work. Could you explain how it work?
pro100andrik94
Posts: 26
Joined: 08 Aug 2018, 07:27

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:07

I just take code of key and send it :)
P.S. First I was try sc138 but it's dont work and than i use vk code.
You can use this code if you need to know another codes of keys

Code: Select all

Menu, Tray, Icon, Shell32.dll, 45 

; клавиши дополнительной клавиатуры и Pause, sc которых ф-ция MapVirtualKey не определяет 
ScVk := "45,13|11D,A3|135,6F|136,A1|137,2C|138,A5|145,90|147,24|148,26|149,21|" 
. "14B,25|14D,27|14F,23|150,28|151,22|152,2D|153,2E|15B,5B|15C,5C|15D,5D" 

; клавиши мыши и их vk, а также Ctrl+Break и Clear 
KeysVK := "LButton,1|RButton,2|Ctrl+Break,3|MButton,4|XButton1,5|XButton2,6|" 
. "Clear,c|Shift,10|Ctrl,11|Alt,12" 

Height := 165 ; высота клиентской области, не включая заголовки вкладок 

Gui, +AlwaysOnTop 
Gui, Color, DAD6CA 
Gui, Add, Tab2, vTab gTab x0 y0 w200 h185 AltSubmit hwndhTab, Tkae a code|Key from code 
Tab = 2 
VarSetCapacity(RECT, 16) 
SendMessage, TCM_GETITEMRECT := 0x130A, 1, &RECT,, ahk_id %hTab% 
TabH := NumGet(RECT, 12, "UInt") 
GuiControl, Move, Tab, % "x0 y0 w200 h" TabH + Height 
Gui, Add, Text, % "x8 y" TabH + 8 " w183 +" SS_GRAYFRAME := 0x8 " h" Height - 16 

Gui, Font, q5 s12, Verdana 
Gui, Add, Text, vAction x15 yp+7 w170 Center c0033BB, Press the key 
Gui, Add, Text, vKey xp yp+35 wp Center Hidden 

Gui, Font, q5 c333333 
Gui, Add, Text, vTextVK xp+8 yp+37 Hidden, vk = 
Gui, Add, Text, vVK xp+35 yp w62 h23 Center Hidden 
Gui, Add, Text, vTextSC xp-35 yp+35 Hidden, sc = 
Gui, Add, Text, vSC xp+35 yp w62 h23 Center Hidden 

Gui, Font, s8 
Gui, Add, Button, vCopyVK gCopy xp+70 yp-35 w50 h22 Hidden, Copy 
Gui, Add, Button, vCopySC gCopy xp yp+33 wp hp Hidden, Copy 

Gui, Tab, 2 
Gui, Add, Text, % "x8 y" TabH + 8 " w183 +" SS_GRAYFRAME " h" Height - 16 
Gui, Add, Text, x15 yp+7 w170 c0033BB 
, Введите код`nв шестнадцатеричном формате без префикса "0x" 

Gui, Font, q5 s11 
Gui, Add, Text, xp yp+58, vk 
Gui, Add, Edit, vEditVK gGetKey xp+25 yp-2 w45 h23 Limit3 Uppercase Center 
Gui, Add, Text, vKeyVK xp+45 yp+2 w105 Center 

Gui, Add, Text, x15 yp+43, sc 
Gui, Add, Edit, vEditSC gGetKey xp+25 yp-2 w45 h23 Limit3 Uppercase Center 
Gui, Add, Text, vKeySC xp+45 yp+2 w105 Center 
Gui, Show, % "w199 h" TabH + Height - 1, codes of keys 

hHookKeybd := SetWindowsHookEx() 
OnExit, Exit 
OnMessage(0x6, "WM_ACTIVATE") 
OnMessage(0x102, "WM_CHAR") 
Return 

Tab: ; whenever the user switches to a new tab, the output variable will 
If (Tab = 2 && !hHookKeybd) ; be set to the previously selected tab number in the case of AltSubmit. 
hHookKeybd := SetWindowsHookEx() 
Else if (Tab = 1 && hHookKeybd) 
DllCall("UnhookWindowsHookEx", UInt, hHookKeybd), hHookKeybd := "" 
Return 

Copy: 
GuiControlGet, Code,, % SubStr(A_GuiControl, -1) 
StringLower, GuiControl, A_GuiControl 
Clipboard := SubStr(GuiControl, -1) . SubStr(Code, 3) 
Return 

GetKey: 
GuiControlGet, Code,, % A_GuiControl 
Code := RegExReplace(Code, "^0+") 
Code := "0x" . Code 
SetFormat, IntegerFast, H 
if A_GuiControl = EditVK 
{ 
if (Code > 0xA5 && Code < 0xBA) 
Key := "", IsKey := 1 

Loop, parse, KeysVK, | 
{ 
if (Substr(Code, 3) = RegExReplace(A_LoopField, ".*,(.*)", "$1")) 
{ 
Key := RegExReplace(A_LoopField, "(.*),.*", "$1") 
IsKey = 1 
Break 
} 
} 

if !IsKey 
{ 
Loop, parse, ScVk, | 
{ 
if (Code = "0x" . RegExReplace(A_LoopField, ".*,(.*)", "$1")) 
{ 
Code := RegExReplace(A_LoopField, "(.*),.*", "0x$1") 
IsCode = 1 
Break 
} 
} 
if !IsCode 
Code := DllCall("MapVirtualKey", UInt, Code, UInt, MAPVK_VK_TO_VSC := 0) 
} 
} 
else if (Code = 0x56 || Code > 0x1FF) 
Key := "", IsKey := 1 

if !IsKey 
Key := GetKeyNameText(Code) 

Key := RegExReplace(Key, "(.*)Windows", "$1Win") 
GuiControl,, % "Key" SubStr(A_GuiControl, -1), % Key 
Key := IsKey := IsCode := "" 
Return 

GuiClose: 
ExitApp 

Exit: 
if hHookKeybd 
DllCall("UnhookWindowsHookEx", Ptr, hHookKeybd) 
ExitApp 

WM_ACTIVATE(wp) 
{ 
global 
if (wp & 0xFFFF = 0 && hHookKeybd) 
DllCall("UnhookWindowsHookEx", UInt, hHookKeybd), hHookKeybd := "" 
if (wp & 0xFFFF && Tab = 2 && !hHookKeybd) 
hHookKeybd := SetWindowsHookEx() 
GuiControl,, Action, % wp & 0xFFFF = 0 ? "Активируйте окно" : "Нажмите клавишу" 
} 

SetWindowsHookEx() 
{ 
Return DllCall("SetWindowsHookEx" . (A_IsUnicode ? "W" : "A") 
, Int, WH_KEYBOARD_LL := 13 
, Ptr, RegisterCallback("LowLevelKeyboardProc", "Fast") 
, Ptr, DllCall("GetModuleHandle", UInt, 0, Ptr) 
, UInt, 0, Ptr) 
} 

LowLevelKeyboardProc(nCode, wParam, lParam) 
{ 
static once, WM_KEYDOWN = 0x100, WM_SYSKEYDOWN = 0x104 

Critical 
SetFormat, IntegerFast, H 
vk := NumGet(lParam+0, "UInt") 
Extended := NumGet(lParam+0, 8, "UInt") & 1 
sc := (Extended<<8)|NumGet(lParam+0, 4, "UInt") 
sc := sc = 0x136 ? 0x36 : sc 
Key := GetKeyNameText(sc) 

if (wParam = WM_SYSKEYDOWN || wParam = WM_KEYDOWN) 
{ 
GuiControl,, Key, % Key 
GuiControl,, VK, % vk 
GuiControl,, SC, % sc 
} 

if !once 
{ 
Controls := "Key|TextVK|VK|TextSC|SC|CopyVK|CopySC" 
Loop, parse, Controls, | 
GuiControl, Show, % A_LoopField 
once = 1 
} 

if Key Contains Ctrl,Alt,Shift,Tab 
Return CallNextHookEx(nCode, wParam, lParam) 

if (Key = "F4" && GetKeyState("Alt", "P")) ; закрытие окна и выход по Alt + F4 
Return CallNextHookEx(nCode, wParam, lParam) 

Return nCode < 0 ? CallNextHookEx(nCode, wParam, lParam) : 1 
} 

CallNextHookEx(nCode, wp, lp) 
{ 
Return DllCall("CallNextHookEx", Ptr, 0, Int, nCode, UInt, wp, UInt, lp) 
} 

GetKeyNameText(sc) 
{ 
VarSetCapacity(Key, A_IsUnicode ? 32 : 16) 
DllCall("GetKeyNameText" . (A_IsUnicode ? "W" : "A"), UInt, sc<<16, Str, Key, UInt, 16) 
if Key in Shift,Ctrl,Alt 
Key := "Left " . Key 
Return Key 
} 

WM_CHAR(wp) 
{ 
global hBall 
SetWinDelay, 0 
CoordMode, Caret 
WinClose, ahk_id %hBall% 
GuiControlGet, Focus, Focus 
if !InStr(Focus, "Edit") 
Return 

if wp in 3,8,24,26 ; обработка Ctrl + C, BackSpace, Ctrl + X, Ctrl + Z 
Return 

if wp = 22 ; обработка Ctrl + V 
{ 
GuiControlGet, Content,, % Focus 
if !StrLen(String := SubStr(Clipboard, 1, 3 - StrLen(Content))) 
{ 
ShowBall("Буфер обмена не содержит текста.", "Ошибка!") 
Return 0 
} 
Loop, parse, String 
{ 
Text .= A_LoopField 
if A_LoopField not in 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F 
{ 
ShowBall("Буфер обмена содержит недопустимые символы." 
. "`nДопустимые символы:`n0123456789ABCDEF", "Ошибка!") 
Return 0 
} 
} 
Control, EditPaste, % Text, % Focus, Коды клавиш 
Return 0 
} 

Char := Chr(wp) 
if Char not in 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F 
{ 
ShowBall("Допустимые символы:`n0123456789ABCDEF", Char " — недопустимый символ") 
Return 0 
} 
Return 
} 

ShowBall(Text, Title="") 
{ 
global 
WinClose, ahk_id %hBall% 
hBall := BalloonTip(A_CaretX+1, A_CaretY+15, Text, Title) 
SetTimer, BallDestroy, -2000 
Return 

BallDestroy: 
WinClose, ahk_id %hBall% 
Return 
} 

BalloonTip(x, y, sText, sTitle = "", h_icon = 0) 
{ 
; BalloonTip — это ToolTip с хвостиком 
; h_icon — 0: None, 1:Info, 2: Warning, 3: Error, n > 3: предполагается hIcon. 

TTS_NOPREFIX := 2, TTS_ALWAYSTIP := 1, TTS_BALLOON := 0x40, TTS_CLOSE := 0x80 

hWnd := DllCall("CreateWindowEx", UInt, WS_EX_TOPMOST := 8 
, Str, "tooltips_class32", Str, "" 
, UInt, TTS_NOPREFIX|TTS_ALWAYSTIP|TTS_BALLOON|TTS_CLOSE 
, Int, 0, Int, 0, Int, 0, Int, 0 
, UInt, 0, UInt, 0, UInt, 0, UInt, 0) 

NumPut(VarSetCapacity(TOOLINFO, A_PtrSize = 4 ? 48 : 72, 0), TOOLINFO, "UInt") 
NumPut(0x20, TOOLINFO, 4, "UInt") ; TTF_TRACK = 0x20 
NumPut(&sText, TOOLINFO, A_PtrSize = 4 ? 36 : 48, "UInt") 

A_DHW := A_DetectHiddenWindows 
DetectHiddenWindows, On 
WinWait, ahk_id %hWnd% 

WM_USER := 0x400 
SendMessage, WM_USER + 24,, w ; TTM_SETMAXTIPWIDTH 
SendMessage, WM_USER + (A_IsUnicode ? 50 : 4),, &TOOLINFO ; TTM_ADDTOOL 
SendMessage, WM_USER + (A_IsUnicode ? 33 : 32), h_icon, &sTitle ; TTM_SETTITLEA и TTM_SETTITLEW 
SendMessage, WM_USER + (A_IsUnicode ? 57 : 12),, &TOOLINFO ; TTM_UPDATETIPTEXTA и TTM_UPDATETIPTEXTW 
SendMessage, WM_USER + 18,, x|(y<<16) ; TTM_TRACKPOSITION 
SendMessage, WM_USER + 17, 1, &TOOLINFO ; TTM_TRACKACTIVATE 

DetectHiddenWindows, % A_DHW 
Return hWnd 
}
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:08

Current this code only works if the cursor is put at a text box. Outside of a textbox IME Hangul/English is disable so it doesn't work.
How to make this toggle work everywhere even outside of a textbox?
pro100andrik94
Posts: 26
Joined: 08 Aug 2018, 07:27

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:15

It's not a code problem. This is windows problem that the input method cannot switch when textbox disabled. Code just simulate pressing key.
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:20

Yes, I have another problems with unikey, is there any way to know its current state (E: English mode or V: Vietnamese mode)?

Image

I used this software from the page for typing Vietnamese: http://unikey.vn/vietnam/
Attachments
unikey.png
unikey.png (190.1 KiB) Viewed 995 times
pro100andrik94
Posts: 26
Joined: 08 Aug 2018, 07:27

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:26

Maybe there is a way. I do not know anything about this program. It is better for you to create a new topic just about this program and ask this question.
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 08:49

I created one but no one answers so far...
Could you help me out? It is a small program to type Vietnamese.
Just press ctrl + shift or alt + z depending on the setting to toggle between Vietnamese and English.
https://autohotkey.com/boards/viewtopic ... 57#p233257
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 09:03

I want to send two keys at the same time ctrl + shift but it doesn't work:

Code: Select all

sendinput, {vkA2} {vkA0}
pro100andrik94
Posts: 26
Joined: 08 Aug 2018, 07:27

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 09:16

It might take a while to figure it out. I can try to deal with this, but I do not guarantee that I will do anything.
And if you are going to send several keys in a row then you need to write it as you wrote. But if you need to press one and then another and release them then you need to write that way

Code: Select all

sendinput, {vkA2 down} 
sendinput, {vkA0 down}
sendinput, {vkA0 up}
sendinput, {vkA2 up} 
anhnha
Posts: 34
Joined: 08 Aug 2018, 02:46

Re: Hangul/English toggle with right Alt key

15 Aug 2018, 09:39

Well, it works now. You are an expert on this!

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], hughman, john68, VonVon and 189 guests