I am trying to create a Programm that pastes given text into a window that does not support ctrl v.
This works except for certain symols, which the keyPress method of the Robot class rejects, although they are defined by the -according to the KeyEvent api- correct constants.
This is an extacted segment of said code in a seperate eclipse project.
running this code throws a Invalid key code Exception for mepublic class Test { //NOSONAR public static void main(String[] a) { int i = KeyEvent.getExtendedKeyCodeForChar('['); System.out.println(i); // prints 91 System.out.println(KeyEvent.VK_OPEN_BRACKET); //prints 91 try (final Scanner scanner = new Scanner(System.in);) { final Robot bot = new Robot(); bot.setAutoDelay(30); // here's the problem bot.keyPress(KeyEvent.VK_OPEN_BRACKET); bot.keyRelease(KeyEvent.VK_OPEN_BRACKET); } catch (Exception e) { e.printStackTrace(); } } }
Console Output:
91
91
java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Unknown Source)
at main.Test.main(Test.java:24)