I want to simulate entering a string (can contain any character) in JTextField. I am using new KeyEventData() for that. But I am not able to determine how to handle characters like {, }, ) etc and also how to append a new character to already entered characters.
You can use Robot
for this, as shown in this example. To get {
, for example, you'll need to do something like this:
keyPress(KeyEvent.VK_SHIFT);
keyPress(KeyEvent.VK_OPEN_BRACKET);
keyRelease(KeyEvent.VK_OPEN_BRACKET);
keyRelease(KeyEvent.VK_SHIFT);
This might be helpful for emulating keyevents: How to simulate keyboard presses in java?
For left and right brace, KeyEvent.VK_BRACELEFT and KeyEvent.VK_BRACERIGHT http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html#VK_BRACELEFT
Hope this helps =]
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