Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect if a users keyboard is in AZERTY in Java?

Tags:

java

javafx

There is currently a bug in JavaFX (https://javafx-jira.kenai.com/browse/RT-30669, free registration required) which makes it so that if you are using an azerty keyboard layout and specify an accelerator with Z in it, on Mac it only fires when typing a W. I need to work around this bug as I need to release my product now.

So I'd like to detect Mac+Azerty and if so change the accelerator to using W. I know how to detect Mac, and I know how to detect the keyboard's locale (using InputContext#getLocale()) but how do I know if the current locale has an azerty keyboard layout? Do I have to check against a hardcoded list of known locales which use an azerty layout? If so, where would I find such a list?

like image 509
Nicolas Mommaerts Avatar asked Jun 09 '13 21:06

Nicolas Mommaerts


1 Answers

Just don't "check against a hardcoded list of known locales" as many people may have a french locale with a keyboard that does not matches the locale, if they bought their computer in the US and use it in quebec with a french interface. I am personally worst, as I'm having a dvorak layout... ;-) And I just want to imagine how many variants of spanish-based layout there may be available...

My best and more portable advice would be to not try to detect something that is hardly detectable, but give some "default" keyboard mappings for (e.g.) qwerty keyboards that would work for most of your userbase, and create a configuration panel that enables your user to change the key mapping for your application by typing the new keys, if they don't like the defaults.

edit:

ah... that can be indeed a different problem... maybe you could anyway make a combobox preference for all non-us keyboard on macosx that has keys with a modifier that get changed?

To answer your question more "straightforwardly", here are a few results I found on google:

  • http://www.coderanch.com/t/412482/java/java/Finding-language-setting-locale-keyboard
  • http://www.java-gaming.org/index.php/topic,23501.

both lead towards java.awt.im.InputContext:

InputContext context = InputContext.getInstance();  
System.out.println(context.getLocale().toString());  

I never tried this in java, so I can't help you more than with my google-fu, but I really hope this helps :-)

like image 167
zmo Avatar answered Nov 09 '22 07:11

zmo