• Advertisement
Sign in to follow this  

Unix/Mac equivalent to GetKeyboardLayoutName?

This topic is 1796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a unix and mac equivalent to the window's function GetKeyboardLayoutName, which retrieve's the system's active input locale identifier?  Thanks!

Share this post


Link to post
Share on other sites
Advertisement

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 getenv("LANG") 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 getenv("LANG") 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

A bummer that Linux does not make it easy.  I will continue to look into it and report back if I figure it out.  Thanks for the reply.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement