GetKeyboardLayout() and LoadKeyboardLayout() difficulty
What i want to do is GetKeyboardlayout(0) that returns a HKL object and i want to use this HKL as input for the first parameter of LoadKeyboardLayout() which is LPCWSTR. Is this possible ?
Thanks in advance
From a cursory test it doesn't appear that there is a direct correlation between the HKL returned from GetKeyboardLayout(0) and the input locale identifier name parameter passed to LoadKeyboardLayout. GetKeyboardLayoutName returns a copy of the string passed to LoadKeyboardLayout.
On my US-English keyboard the default value returned by GetKeyboardLayoutName was string "00000409" while the HKL returned from GetKeyboardLayout(0) was 0x04090409 (32-bit) test. After changing the keyboard layout to US-Dvorak by passing string "00010409" to LoadKeyboardLayout the HKL returned by GetKeyboardLayout was 0xF0020409.
So on the surface, it doesn't seem like the HKL would be a suitable parameter to pass to LoadKeyboardLayout.
Is it possible to convert is somehow to be usable within LoadKeyboardLayout ?
Maybe you can use an approximation:
Do you want to duplicate the HKL for some different process?
The low word of the HKL will provide language but that approximation does not provide for the physical layout. Using the example that I mentioned earlier passing the approximation based on language alone could reset the physical layout of the keyboard, probably an unintended side effect.
Also, there are keyboard identifiers documented at windows-language-pack-default-values for which the high order word is not 0x0000.
Why do you want to load a keyboard layout that is already loaded, that you already have a handle for? This sounds like an XY problem. What are you really trying to achieve?
Sign in to comment