Is there a unix and mac equivalent to the window's function GetKeyboardLayoutName, which retrieve's the system's active input locale identifier? Thanks!
Unix/Mac equivalent to GetKeyboardLayoutName?
#2 Senior Moderators - Reputation: 4749
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 - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#3 Members - Reputation: 167
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 Senior Moderators - Reputation: 4749
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 - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]






