adamgal Posted April 20, 2005 Share Posted April 20, 2005 Does anyone know a way to detect the language the user is typing in? I tried dllcall with getcurrentkeyboardlayout but that only returns the default keyboard layout. anyone have any other ideas? Link to comment Share on other sites More sharing options...
dok_do Posted April 20, 2005 Share Posted April 20, 2005 (edited) my english is very poor,sorry it is visual basic code. you will convert autoit code using dllcall() i am newbie,so i don't convert autoit code. sorry Declare Function GetKeyboardLayout Lib "user32" _ (ByVal dwLayout As Long) As Long Declare Function ImmGetDescription Lib "imm32" Alias "ImmGetDescriptionA" _ (ByVal hKL As Long, _ ByVal lpszDescription As String, _ ByVal uBufLen As Long) As Long Dim lngKeyboardLayoutHandle As Long Dim strIMEDescription As String * 128 Dim lngWin32apiResultCode As Long lngKeyboardLayoutHandle = GetKeyboardLayout(0) lngWin32apiResultCode = ImmGetDescription(lngKeyboardLayoutHandle, _ strIMEDescription, _ Len(strIMEDescription)) Label2.Caption = Left(strIMEDescription, _ InStr(strIMEDescription, vbNullChar) - 1) Edited April 20, 2005 by dok_do Link to comment Share on other sites More sharing options...
jpm Posted April 20, 2005 Share Posted April 20, 2005 $userkeyboard=RegRead("HKCU\Keyboard Layout\Preload","1") it should return something equivalent to @OSLANG Link to comment Share on other sites More sharing options...
CyberSlug Posted April 20, 2005 Share Posted April 20, 2005 I wonder if RegRead("HKCU\Keyboard Layout\Preload","1") will work in this case... dok_do is probably on the right track. If someone alternates between English and Japanese, for example, you probably need a DllCall that reads IME information.... (If I remember from a computer I helped set up, Japanese could be especially tricky since the language bar lets you choose "Direct Input" or "Hiragana" or "Katakana" ....) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Guest cvi Posted June 6, 2005 Share Posted June 6, 2005 I wonder if RegRead("HKCU\Keyboard Layout\Preload","1") will work in this case..........I tried it and it didn't work. I needed to know if the keyboard is set to Hebrew or English, and this function returned 409 (English), that is, the default setting and not the active one.Cvi Link to comment Share on other sites More sharing options...
Lazycat Posted June 6, 2005 Share Posted June 6, 2005 (edited) I don't found any references for "getcurrentkeyboardlayout". Maybe you mean "GetKeyboardLayoutName"? Anyway, try this code (works with beta only!). Because under NT's keyboard layout remember for each program, try to change layout in the inputbox. InputBox("InputBox", "Try change layout here and press key") $p = DllStructCreate("char[9]"); $KL_NAMELENGTH = 9 $ret = DllCall("user32.dll", "int", "GetKeyboardLayoutName", "ptr", DllStructGetPtr($p)) MsgBox (0, "title", DllStructGetData($p, 1)) DllStructDelete($p) Edited June 6, 2005 by Lazycat Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
Guest cvi Posted June 7, 2005 Share Posted June 7, 2005 I don't found any references for "getcurrentkeyboardlayout". Maybe you mean "GetKeyboardLayoutName"? Anyway, try this code (works with beta only!). Because under NT's keyboard layout remember for each program, try to change layout in the inputbox.Thanks for the fast answer.I have not tried it yet - because if the keyboard layout is remembered for each program, then it won't help me anyway.My original problem was that something like:send("H:\TAG_2005\AZMANCVI.DOC")that worked with English keyboard, won't work with Hebrew keyboard layout because the "." is mapped in it to the key that has "?" in English.So, I wanted to check the keyboard language, and change it if necessary.If this change would affect only Autoit, and not the program receiving it - that won't help.Cvi Link to comment Share on other sites More sharing options...
Lazycat Posted June 7, 2005 Share Posted June 7, 2005 (edited) After some digging I come to following code: Opt("WinTitleMatchMode", 4) Run("notepad.exe") Sleep(500) $hWnd = WinGetHandle("classname=Notepad") MsgBox (0, "Old Layout", _GetKeyboardLayout($hWnd)) _SetKeyboardLayout("00000409", $hWnd) MsgBox (0, "New Layout", _GetKeyboardLayout($hWnd)) Func _GetKeyboardLayout($hWnd) Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0) $ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0]) Return "0000" & Hex($ret[0], 4) EndFunc Func _SetKeyboardLayout($sLayoutID, $hWnd) Local $WM_INPUTLANGCHANGEREQUEST = 0x50 Local $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 0) DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, _ "int", $WM_INPUTLANGCHANGEREQUEST, _ "int", 1, _ "int", $ret[0]) EndFunc This more generic instead previous sample. You can get or set layout for given window. Hope this helps. Edited June 7, 2005 by Lazycat Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
Guest cvi Posted June 7, 2005 Share Posted June 7, 2005 After some digging I come to following code:This more generic instead previous sample. You can get or set layout for given window.Hope this helps.<{POST_SNAPBACK}>Thanks!It is just what I needed - it does work (at least in NOTEPAD as in your example. I hope it will also in real use)I wrote alternating Hebrew and latin letters, looks good.Cvi Link to comment Share on other sites More sharing options...
log54321_tw Posted January 29, 2007 Share Posted January 29, 2007 ThanK A LOT. Link to comment Share on other sites More sharing options...
chenxu Posted September 9, 2007 Share Posted September 9, 2007 After some digging I come to following code:This more generic instead previous sample. You can get or set layout for given window.Hope this helps.This is just what I need, thanks a lot Link to comment Share on other sites More sharing options...
Tiger Posted September 9, 2007 Share Posted September 9, 2007 Use this expandcollapse popupMsgBox(0, "Your Keyboard Language:", _Language()) Func _Language() $language = RegRead("HKCU\Keyboard Layout\Preload","1") Select Case StringInStr("0413,0813", $language) Return "Dutch" Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", $language) Return "English" Case StringInStr("040c,080c,0c0c,100c,140c,180c", $language) Return "French" Case StringInStr("0407,0807,0c07,1007,1407", $language) Return "German" Case StringInStr("0410,0810", $language) Return "Italian" Case StringInStr("0414,0814", $language) Return "Norwegian" Case StringInStr("0415", $language) Return "Polish" Case StringInStr("0416,0816", $language) Return "Portuguese" Case StringInStr("040a,080a,0c0a,100a,140a,180a,1c0a,200a,240a,280a,2c0a,300a,340a,380a,3c0a,400a,440a,480a,4c0a,500a", $language) Return "Spanish" Case StringInStr("041d,081d", $language) Return "Swedish" Case Else Return "Other (can't determine with $language directly)" EndSelect EndFunc My UDFs:- _RegEnumKey Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 9, 2007 Moderators Share Posted September 9, 2007 Use this expandcollapse popupMsgBox(0, "Your Keyboard Language:", _Language()) Func _Language() $language = RegRead("HKCU\Keyboard Layout\Preload","1") Select Case StringInStr("0413,0813", $language) Return "Dutch" Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", $language) Return "English" Case StringInStr("040c,080c,0c0c,100c,140c,180c", $language) Return "French" Case StringInStr("0407,0807,0c07,1007,1407", $language) Return "German" Case StringInStr("0410,0810", $language) Return "Italian" Case StringInStr("0414,0814", $language) Return "Norwegian" Case StringInStr("0415", $language) Return "Polish" Case StringInStr("0416,0816", $language) Return "Portuguese" Case StringInStr("040a,080a,0c0a,100a,140a,180a,1c0a,200a,240a,280a,2c0a,300a,340a,380a,3c0a,400a,440a,480a,4c0a,500a", $language) Return "Spanish" Case StringInStr("041d,081d", $language) Return "Swedish" Case Else Return "Other (can't determine with $language directly)" EndSelect EndFuncThis doesn't work for me (My layout is 00000409)... so the StringInStr will fail Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 9, 2007 Moderators Share Posted September 9, 2007 This might get you the results your looking for more efficiently Tiger:Func _CurrentLang() Local $sLanNum = "0413,0813|0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809," & _ "2c09,3009,3409|040c,080c,0c0c,100c,140c,180c|0407,0807,0c07,1007," & _ "1407|0410,0810|0414,0814|0415|0416,0816|040a,080a,0c0a,100a,140a," & _ "180a,1c0a,200a,240a,280a,2c0a,300a,340a,380a,3c0a,400a,440a,480a," & _ "4c0a,500a|041d,081d" Local $aLanName = StringSplit("Dutch|English|French|German|Italian|" & _ "Norwegian|Polish|Portuguese|Swedish", "|") Local $aLanNum = StringSplit($sLanNum, "|") Local $sLang = StringRight(RegRead("HKCU\Keyboard Layout\Preload","1"), 4) If $sLang = "" Then Return SetError(1, 0, "Not Defined") For $iCC = 1 To UBound($aLanNum) - 1 If StringInStr($aLanNum[$iCC], $sLang) Then Return $aLanName[$iCC] Next Return SetError(2, 0, "Other") EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
illidan333 Posted October 18, 2021 Share Posted October 18, 2021 On 6/7/2005 at 3:45 AM, Lazycat said: After some digging I come to following code: Opt("WinTitleMatchMode", 4) Run("notepad.exe") Sleep(500) $hWnd = WinGetHandle("classname=Notepad") MsgBox (0, "Old Layout", _GetKeyboardLayout($hWnd)) _SetKeyboardLayout("00000409", $hWnd) MsgBox (0, "New Layout", _GetKeyboardLayout($hWnd)) Func _GetKeyboardLayout($hWnd) Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0) $ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0]) Return "0000" & Hex($ret[0], 4) EndFunc Func _SetKeyboardLayout($sLayoutID, $hWnd) Local $WM_INPUTLANGCHANGEREQUEST = 0x50 Local $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 0) DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, _ "int", $WM_INPUTLANGCHANGEREQUEST, _ "int", 1, _ "int", $ret[0]) EndFunc This more generic instead previous sample. You can get or set layout for given window. Hope this helps. I tried this code, the read function works for me, but the set function didn't my language was chinese 0084, but after running the set function, it stays any 0084. Can you please help? thanks Link to comment Share on other sites More sharing options...
illidan333 Posted October 18, 2021 Share Posted October 18, 2021 1 minute ago, illidan333 said: I tried this code, the read function works for me, but the set function didn't my language was chinese 0084, but after running the set function, it stays any 0084. Can you please help? thanks nvm i figured it out, the issue i had is because the window handler i had was invalid. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now