Jump to content

Change the Keyboard Layout/Input Language


sb1920alk
 Share

Recommended Posts

I'm trying to set the default keyboard language in a logon script for users in other countries who use the same Default User template as everyone else. I put together the script below from bits and pieces I found in other threads. I call it with a parameter like 00000409 or 00000809. It works fine for all of the windows that are open, but if I open a new window, it uses the original input layout. What I need is to reproduce the effect of setting it in Control Panel\Regional and Language Options\Languages\Details...\Default input language., but even that doesn't seem to do the change right away. Typing in the Run line gives me the old language and in a new notepad window gives me the new language. Setting HKEY_CURRENT_USER\Keyboard Layout\Preload is great, but it doesn't take effect until the next logon.

If $CmdLine[0] <> 1 Then Exit(1)

$KeyBoardLayoutCode = $CmdLine[1]
$allwindows = WinList()
For $i = 1 to $allwindows[0][0]
    If IsVisible($allwindows[$i][1]) Then
        _SetKeyboardLayout($KeyBoardLayoutCode, $allwindows[$i][1])
    EndIf
Next

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

Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc

I tried it for all windows instead of just the visible ones, but it didn't make any difference.

How can I change the keyboard language for all programs, and new windows without logging off and logging back on?

Thanks.

[Edit: Spelling]

Edited by sb1920alk
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...