Keyboard layout - language ID

Hello!

How can I get current language ID without using platform-specific functions (such as GetKeyboardLayout in Windows) ?
I tried use FCulture::GetKeyboardLayoutId() for current culture, but it always returns 0.

Thanks.

Looking in the code there is some LegacyCulture information but is disabled by a define:

#if !UE_ENABLE_ICU

and the actual function doesn’t look to be implemented in the Engine for whatever reason right now:

int FCulture::FICUCultureImplementation::GetKeyboardLayoutId() const
{
	return 0;
}

You’ll want to use the FInternationalization::Get().GetCurrentCulture().

From the culture you can access the various ISO codes that represent the culture.

I tried this and always get “en”, how I can get current language of window ?

The default behavior for the engine is to get the current language of the OS. If you’ve ever manually set a language though in the engine, editor, or ini file that setting will override the OS language.

If you open up your Region and Language settings in Windows you can change your “Format”. If that doesn’t work then you have a setting overriding your default locale.

You can also specify culture=jp on the cmdline or in the application using the console window.

What locale are you trying/expecting to get?

Hmm… so the keyboard layout concept should be separate from the current culture. So if you’re typing on a Russian keyboard then it shouldn’t matter what your current culture is, it should type Russian characters.

It’s my understanding that should already work as Windows should forward us the appropriate character, unless you’re using some kind of IME in which case we also have support for that.

I’m going to pull in some other people to help you as I don’t think chasing up the culture information is actually what you want.

In my case, it doesn’t work (setting Culture=ru has no effect)

In Region and Language settings I can change “Format” (by default - Russian)

My goal - handle input characters from keyboard in both layouts (RU/EN), not setting up on app start; when user switched language to RU, GetCurrentCulture indicates EN, so I need something like GetKeyboardLayout in WinAPI.

1 Like