Java robot class fails with nordic characters

I’m finnish man and letters Å, Ä and Ö (especially Ä and Ö) are necessary letters in some situations (if you cannot see these letters then you should probably change your browsers character encoding to something like western (ISO-8859-1)). These characters seem to be causing problems in my program which uses Robot class.

My programs idea is to read string from JTextField and write it to combobox letter by letter in my internet browser. This may sound bizarre idea but I didn’t find any other easy solution to highlight specific item in combobox than writing text in it. Anyway the reason why i need to do it isn’t important but I would like to know how I could avoid my program tilting when it gets nordic characters. Following code works if charAt(i) != å, ä or ö. But if charAt(i)==å,ä or ö then program fails and throws exceptions.

for(int i = 0; i < thisString.length();i++)
{
robot.keyPress(theString.charAt(i));
robot.keyRelease(theString.charAt(i));
}

Can I solve this problem somehow or is Robot class made only to american type of keyboard settings?

I got these exceptions:

Exception in thread “Thread-2” java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Robot.java:224)
at javaapplication3.JFrame.AI(JFrame.java:392)
at javaapplication3.JFrame.run(JFrame.java:427)
at java.lang.Thread.run(Thread.java:619)

Actually, it fails for a lot of ‘regular’ keys too… like…

VK_PLUS vs VK_EQUALS

You can pretty easily solve it by not sending the normal keyevents, but sending keyevents like ALT + unicode digits

If you want the ñ, it’d look like:

PRESS ALT
PRESS VK_0 (digits on numpad)
RELEASE VK_0
PRESS VK_2
RELEASE VK_2
PRESS VK_4
RELEASE VK_4
PRESS VK_1
RELEASE VK_1
RELEASE ALT

Thanks for helping me to keep it simple! I was actually thinking that but I hoped there was better way.

Now that I know that there isn’t any good solution I am going to do it like you said and stop wasting time googling for solution.