Forums


Comfort Software :: Forums :: Development
<< Previous thread | Next thread >>   

Programmaticaly change keybaord language

Author Post
chell
Fri Jul 03 2009, 04:50am
Registered Member #313
Joined: Fri Jul 03 2009, 04:30am
Posts: 1
Hi,

How can I change programmaticaly the keybaord language (like with the language bar by clicking with the mouse). I'm using .NET/C#. Currently I can Show/Hide/Toggle ... the keyboard whithout any problem.

Thanks
Christophe

Back to top
Comfort
Fri Jul 03 2009, 11:07am


Joined: Wed Sep 19 2007, 03:42pm
Posts: 568
Try message WM_INPUTLANGCHANGEREQUEST.
Like:
SendMessage(GetForegroundWindow, WM_INPUTLANGCHANGEREQUEST, 0, NewHKL)

Have a nice day
Back to top
PVitt
Tue May 17 2011, 07:49am
Registered Member #829
Joined: Tue May 17 2011, 07:41am
Posts: 5
Hello,

Just an example, problem occurs with all langauges:
I have the portugese (Brasil) language file (pt.txt) in the Lang folder. When I post the appropriate language ID (1046) as you described above, the language bar switches to Portugese (Brasil), but the keyboard layout doesn't change. When I then click on the language bar, it stays on Purtugese (Brasil) and changes the keyboard layout. But I want to change the Kexboard layout without having the user to use the language bar.

Where is my mistake?

Thanks in advance,
Peter
Back to top
Comfort
Tue May 17 2011, 08:09am


Joined: Wed Sep 19 2007, 03:42pm
Posts: 568
Try to use full Langauage ID. You can find Language ID in field Options -> Keys -> Show keyboard layout by default.

Hexadecimal Language ID for Portugese (Brasil) is 0xF0100416

But some applications don't support message WM_INPUTLANGCHANGEREQUEST.

Have a nice day
Back to top
PVitt
Wed May 18 2011, 04:09am
Registered Member #829
Joined: Tue May 17 2011, 07:41am
Posts: 5
Thanks for the quick reply, but this also doesn't work. Neither 0xF0100416 nor 0x04160416 as statet at "Options -> Keys -> Show keyboard layout by default" does the trick. Here is the code I use:

[DllImport( "user32.dll", EntryPoint = "FindWindow" )]
private static extern Int32 FindWindow( string className, string windowName );

[DllImport( "User32.DLL" )]
private static extern Boolean PostMessage( Int32 hWnd, Int32 msg, Int32 wParam, Int32 lParam );

private const string ClassName = "TFirstForm";
private const string WindowName = "CKeyboardFirstForm";
private const Int32 WM_INPUTLANGCHANGEREQUEST = 0x0050;

private void ChangeKeyboardLayout( int keyboardLocale )
{
    Int32 hWnd = FindWindow( ClassName, WindowName );
    PostMessage( hWnd, WM_INPUTLANGCHANGEREQUEST, 0, keyboardLocale );
}
Back to top
Comfort
Wed May 18 2011, 05:00am


Joined: Wed Sep 19 2007, 03:42pm
Posts: 568
This is incorrect code!
You have to send message WM_INPUTLANGCHANGEREQUEST to foreground window:
SendMessage(GetForegroundWindow, WM_INPUTLANGCHANGEREQUEST, 0, NewHKL)

Have a nice day
Back to top
PVitt
Wed May 18 2011, 05:19am
Registered Member #829
Joined: Tue May 17 2011, 07:41am
Posts: 5
Thanks. That was the error I made. Here is the code that works:

[DllImport( "user32.dll" )]
private static extern IntPtr GetForegroundWindow( );

[DllImport( "user32.dll", CharSet = CharSet.Auto )]
private static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam );

private const Int32 WM_INPUTLANGCHANGEREQUEST = 0x0050;

private void ChangeKeyboardLayout( int keyboardLocale )
{
    IntPtr hWnd = GetForegroundWindow( );
    SendMessage( hWnd, WM_INPUTLANGCHANGEREQUEST, (IntPtr)0, (IntPtr)keyboardLocale );
}
Back to top
Moderators: Comfort

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System