0

I use the robot class in my Java Code. I want to press the key "_" but the keycode 189 doesn't work for the Code

public void type() throws Exception

Robot rob = new Robot();

rob.keyPress(189);
rob.keyRelease(189);

2 Answers 2

3

The proper way is to use SHIFT + -.

Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_SHIFT);
rob.keyPress(KeyEvent.VK_MINUS);
rob.keyRelease(KeyEvent.VK_MINUS);
rob.keyRelease(KeyEvent.VK_SHIFT);

It seems that on a French keyboard following code would work, as the keyboard as a designated underscore key:

Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_UNDERSCORE);
rob.keyRelease(KeyEvent.VK_UNDERSCORE);

From this source they say:

Numbers are not prioritized

Writing the numbers on a French keyboard requires using the shift key each time.

That means the AZERTY keyboard prioritizes things like the accented letters (such as é) and brackets - and even the ampersand (&) over numbers.

enter image description here

Looking at the 8 key, you can find the underscore.

0
0

This is caused by the keyboard layout not having an actual underscore key. To get an underscore, you have to press Shift + - (minus).

rob.keyPress(KeyEvent.VK_SHIFT);
rob.keyPress(KeyEvent.VK_MINUS);
rob.keyRelease(KeyEvent.VK_MINUS);
rob.keyRelease(KeyEvent.VK_SHIFT);

Source

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.