My current project involves automation using Java’s Robot class, to simulate key presses.
My problem is that certain keycodes are invalid to pass to the Robot’s keypress(int keycode) method.
What I already know:
After reading the solution to this question: Why are some KeyEvent keycodes throwing IllegalArgumentException: Invalid key ocode, I started modifying my code, changing certain symbols like £ (VK_DOLLAR) to VK_SHIFT + VK_3, & (VK_AMPERSAND) to VK_SHIT + VK_7, etc …
My question:
My question, however is how to determine what key gives what symbol when combined with shift, since different keyboards (and often times different keyboard configurations from the OS) change these.
A typical example is the @ (at symbol) and " (double quote). VK_SHIFT + VK_2 may be the at symbol on some systems while maybe a double quote on others.
Is there anyway in Java to check, prior to invoking the Robot keypress, on which key a symbol relies ?
Thanks in advance.
I already went through IllegalArgumentException when using robots. It’s because of your keyboard layout. My solution was to use Alt codes:
It makes easy to send Alt codes.
For example, if you want an ampersand just use
alt(KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD3, KeyEvent.VK_NUMPAD8);You just got to make sure Num Lock is on.
A useful site to get the alt codes you’ll need is http://www.alt-codes.net/