Determining the keyboard layout in a running application

How do I determine, within a running application, what keyboard layout is currently being used by the computer? For instance, how do I determine if the keyboard layout is English US, English GB, French, Finish, Swedish, etc.?

Thanks.

If all you need is to make sure the appropriate keyboard is used, a simple idea would be to track keyboard activity in keydown, and compare with Keyboard.AsyncKeydown for certain keys to see what they generate. See http://documentation.xojo.com/index.php/Keyboard

For instance key&H13 in the US keyboard generates “2” and in the French keyboard “é”.

Similarly, the key right next to the left uppercase generates “`” on the Mac US keyboard and “<” on the French keyboard. That particular key is used by Apple to detect the type of keyboard as well.

You could use regular user input to do that, or ask the user to type a certain key.

The current keyboard layout is stored into the system, so it is possible to get that information from the system in both Mac and Windows. But that means using declares, and I do not recall ever seeing such methods.

Thanks Michel.
What I need is to determine before the user has pressed any key, what the keyboard layout is.
As it turns out, it is quite simple. I realised (after some digging around in the documentation for help on keyboards and then posting the message and then more digging and finally understanding the section on localisation) that with string constants there is a dynamic check box which when set allows the system to change the text displayed based on the language / keyboard layout of the computer. From the few tests that I have done, this seems to satisfy my needs.
So for now, I think I’m sorted.
Thanks again.

[quote=166232:@Martin McAvoy]Thanks Michel.
What I need is to determine before the user has pressed any key, what the keyboard layout is.
As it turns out, it is quite simple. I realised (after some digging around in the documentation for help on keyboards and then posting the message and then more digging and finally understanding the section on localisation) that with string constants there is a dynamic check box which when set allows the system to change the text displayed based on the language / keyboard layout of the computer. From the few tests that I have done, this seems to satisfy my needs.
So for now, I think I’m sorted.
Thanks again.[/quote]

The locale will only tell you the display language. Not the keyboard used. I personally use a system set for EN-US with a French keyboard. It is not a common occurrence, but it does happen.

I am sure the information about the current keyboard layout exists in the system, though.

You’re not allow in your system set up and it’s not too uncommon to have it the other way round - foreign language with a EN-US keyboard.

Thanks again. I’ll keep digging.

For Windows, GetKeyboardLayout() provides the info.
Here is a page of a VB.NET program that should be fairly easy to translate to xojo :
VBnet™ Visual Basic Developers Resource Centre

I found a very easy way, though. The registry contains the information about the user keyboard layout at
HKEY_CURRENT_USER\Keyboard Layout\Substitutes

Key d0010409 (possibly 00000409 on other systems) contains the language. For me 0000040c which is the code for French. A complete list of codes is available at ITPro Today: IT News, How-Tos, Trends, Case Studies, Career Tips, More

You can examine the registry by pressing Window-R then type regedit. Xojo has access to the registry through the Registry item :
http://documentation.xojo.com/index.php/Registry

For Mac, all I could find was for Carbon. I am not versed well enough in Cocoa’s intricacies to even guess where it could be now. Maybe the Carbon methods still works.