Java Robot with Azerty vrs Qwerty
Asked Answered
S

1

2

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

Streak answered 8/2, 2013 at 5:47 Comment(0)
P
2

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

Polarize answered 8/2, 2013 at 6:6 Comment(2)
The linked repository is dead nowadays. It hardly hosts any material any more. Is there an updated link available?Cabbala
I think the project has moved to github. The keyboard relevant part is in github.com/holgerbrandl/windowlicker/tree/master/src/core/main/…Requirement

© 2022 - 2024 — McMap. All rights reserved.