The MindFusion Forums
Virtual Keyboard Components >> WPF >> Input locale not set in stand alone mode
https://mindfusion.eu/Forum/YaBB.pl?num=1496761394

Message started by damiano on Jun 6th, 2017 at 3:03pm

Title: Input locale not set in stand alone mode
Post by damiano on Jun 6th, 2017 at 3:03pm
Hello,

I am using your WPF VirtualKeyboard control. I need it to behave like Windows on screen keyboard, so I set IsStandAlone to true. This works fine.

I also would like to set InputLocale programmatically, but when I try to set this property nothing happens.

Could someone help me please ?

Thanks

Title: Re: Input locale not set in stand alone mode
Post by Slavcho on Jun 6th, 2017 at 5:49pm
Hi,

Right, this setter only calls ActivateKeyboardLayout API function which changes input language of current (yours) process. So the keyboard tracks input language in foreground window and sets InputLocale automatically to match it, overriding your value. If you need to toggle between installed languages in target application, you could call keyboard.SendKey(Key.Lang) instead - this sends a WM_INPUTLANGCHANGEREQUEST to the foreground window and leads to ActivateKeyboardLayout being called in that application's process.

Regards,
Slavcho

Title: Re: Input locale not set in stand alone mode
Post by damiano on Jun 7th, 2017 at 7:13am
Hi,

thank you for the quick answer. Toggleing layout with keyboard.SendKey(Key.Lang) is not exactly what I tried to do. Finally I could select a locale by calling PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, MYLOCALE);

Title: Re: Input locale not set in stand alone mode
Post by Bleary Eye on Aug 17th, 2017 at 1:29pm

Slavcho wrote on Jun 6th, 2017 at 5:49pm:
If you need to toggle between installed languages in target application, you could call keyboard.SendKey(Key.Lang) instead - this sends a WM_INPUTLANGCHANGEREQUEST to the foreground window and leads to ActivateKeyboardLayout being called in that application's process. Slavcho

I need to switch keyboard language in the application only. The system language must always be English. I tried the SendKey mentioned but Key.Lang does not exist. What do I need to do?

Title: Re: Input locale not set in stand alone mode
Post by Slavcho on Aug 17th, 2017 at 1:53pm
It might be called Key.LANG in older versions of the control.

Title: Re: Input locale not set in stand alone mode
Post by Bleary Eye on Aug 21st, 2017 at 9:14pm
I have the keyboard in a separate window similar to the example that was installed. I have code like:


Quote:
VirtualKeyboard.Language = XmlLanguage.GetLanguage("es-mx");
VirtualKeyboard.SendKey(Key.Lang);


VirtualKeyboard.Language is set correctly and stays set, but the display remains English rather than Spanish. I tried the SendKey as you suggested above but no difference. I tried other languages, same result.

I also tried the suggestion in https://stackoverflow.com/a/14750885, putting the code in the window hosting the keyboard, but that didn't work either.

What should i try?

Title: Re: Input locale not set in stand alone mode
Post by Bleary Eye on Aug 21st, 2017 at 9:40pm
Another note. I can change languages by clicking the language button. But I don't just want to toggle. I'll have a list of about 15 languages and have to be able to specify precisely which one.

What's the code that's executed when the language key is pressed?

Title: Re: Input locale not set in stand alone mode
Post by Bleary Eye on Aug 21st, 2017 at 10:11pm
After more checking online and trial, here's what works:


Quote:
InputLanguageManager.Current.CurrentInputLanguage = cultureInfo;


This does not change the overall system language (stays English); that's good. However, it also does not change what's displayed in the keyboard language key. That's a nuisance but not fatal.

Title: Re: Input locale not set in stand alone mode
Post by Slavcho on Aug 22nd, 2017 at 8:12pm

Quote:
VirtualKeyboard.Language = XmlLanguage.GetLanguage("es-mx");

This XmlLanguage property is defined in base FrameworkElement and is not used by the keyboard control. Instead you could set keyboard.InputLocale = new CultureInfo("es-mx");

This will have effect mostly when not in stand-alone mode, which sets InputLocale automatically depending on foreground window's current language.

The Lang key sends WM_INPUTLANGCHANGEREQUEST to foreground window. As Damiano noted above you can call
PostMessage(hWnd, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, MYLOCALE) to request a specific language.

Regards,
Slavcho

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.