Sign in to follow this  
myers80

Unix/Mac equivalent to GetKeyboardLayoutName?

Recommended Posts

I don't really think that Mac/Linux have the concept of an input locale that is separate from the system locale, but I could be mistaken.

 

If you just want the current system locale, something like this should be sufficient:

 

#include <locale>
 
int main()
{
    std::locale current;
    std::cout << current.name() << std::endl;
}

 

You could also call [tt]getenv("LANG")[/tt] to query the shell's locale.

Share this post


Link to post
Share on other sites

I don't really think that Mac/Linux have the concept of an input locale that is separate from the system locale, but I could be mistaken.

 

If you just want the current system locale, something like this should be sufficient:

 

 

#include <locale>
 
int main()
{
    std::locale current;
    std::cout << current.name() << std::endl;
}

 

You could also call [tt]getenv("LANG")[/tt] to query the shell's locale.

 

I'm not sure the system locale is what I'm looking for.  I need a way to determine what the keyboard's layout is (i.e. qwerty or dvorak).  So far it looks like XkbLayout might have this information.  Does anyone know if that is the case?

Share this post


Link to post
Share on other sites

I need a way to determine what the keyboard's layout is (i.e. qwerty or dvorak).

Ah, sorry, the use of the term 'locale' confused me.

 

On Mac you need to use the Text Input Source Services.

 

On Linux things are a bit of a nightmare, maybe the source of the xkb-switch utility will be useful to you. I'm fairly sure that this isn't possible to accomplish in a robust fashion under X, however - on my box, Gnome seems to disagree with X about the active keyboard layout.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this