I know how to have Robot simulate a Y keypress like so:
Robot.keyPress(KeyEvent.VK_Y);
But how do I get Robot to press a quote and period?:
".
Can anyone provide me some reference page or sample code?
The Robot class in the Java AWT package is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.
The primary purpose of Robot is to facilitate automated testing of Java platform implementations. Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue.
You can't always just use the KeyEvent.VK... variable.
For example on my keyboard the "%" character is above the "5". To use a Robot to type a "5", the code would be:
robot.keyPress(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_5);
and use a Robot to type a "%", the code would be:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_SHIFT);
If you wanted to use Robot, KeyEvent has VK_QUOTE and VK_PERIOD constants. All of these constants and more are available through the KeyEvent API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With