Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Unix/Mac equivalent to GetKeyboardLayoutName?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 myers80   Members   -  Reputation: 194

Like
0Likes
Like

Posted 19 February 2013 - 05:00 PM

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



Sponsor:

#2 swiftcoder   Senior Moderators   -  Reputation: 10242

Like
0Likes
Like

Posted 19 February 2013 - 07:15 PM

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.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#3 myers80   Members   -  Reputation: 194

Like
0Likes
Like

Posted 19 February 2013 - 09:03 PM

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?



#4 swiftcoder   Senior Moderators   -  Reputation: 10242

Like
1Likes
Like

Posted 19 February 2013 - 09:41 PM

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.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#5 myers80   Members   -  Reputation: 194

Like
1Likes
Like

Posted 20 February 2013 - 07:53 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS