Java Robot with Azerty vrs Qwerty

戏子无情 提交于 2019-12-01 11:12:30

问题


I hope this isn't a duplicate, but I've scoured the forums and have yet to find any answers.

I am having issues with my java application using the Robot class to type text. The text is provided and the application types it out. When the user has a QWERTY keyboard everything works fine. When the user has an AZERTY keyboard the values come out incorrectly.

For example feeding "1234567890" into the software types "&é"'(§è!çà"

I'm hoping some people have an idea how to support multiple keyboard layouts. Thank you in advance.

Here is a snippet

String TRANSLATION_SHIFT = "~!@#$%^&*()_+{}|:\"<>?";
String TRANSLATION_NON_SHIFT = "`1234567890-=[]\\;',./";
Robot robot = new Robot();
String text = "1234567890";
int key;
for (char c: text.toCharArray()){
  switch(c){
    ....
    case '0':
      key = KeyEvent.VK_0;
      break;
case '1':
  key = KeyEvent.VK_1;
  break;
...(etc etc)...
case '9':
  key = KeyEvent.VK_9;
  break;
    ...
  }
  robot.keyPress(key);
  robot.keyRelease(key);
}

There is also code in there to


回答1:


I think you will need to be aware of the Keyboard layout, I am not sure if there is some built-in function to specify the locale to the Robot class, but you can find an wrapper implementation for Robot class that support different keyboard layouts see this library



来源:https://stackoverflow.com/questions/14766470/java-robot-with-azerty-vrs-qwerty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!