virtual keyboard whith Robot.keyPress

L

Linus Sylv?n

Hi I'm trying to make a "virtual keyboard" in java.

And the problem is that Java's Robot class two methods
void keyPress(int keycode)
void keyRelease(int keycode)
takes an int as argument and there doesn't seem to be codes for the
Swedish letters Å å, Ä ä, Ö ö

Are there codes for these letters? (Guess not I tried every code from
0 to 2024).
If not, is there any workaround or trick I could use?

I tried to generate KeyEvents with
Int id=401;
e = new KeyEvent(this, id, 0, 0, 0, 'ö');
kfm.dispatchKeyEvent(e);

but they don't leave the java application and that exactly what I want
them to do, write to Microsoft's word for example, the focusing
problem and the widows z-order problem are more or less solved via
native c programming and JNI wrapping.

So focus is set to the other receiving app at the time when the
keyevent dispatches: works with the Robot.

Do I have to generate these 3 keypress events with native programming
or is there a way to do this in Java??

Regards Linus Sylvén
 
J

JScoobyCed

Linus said:
Hi I'm trying to make a "virtual keyboard" in java.

And the problem is that Java's Robot class two methods
void keyPress(int keycode)
void keyRelease(int keycode)
takes an int as argument and there doesn't seem to be codes for the
Swedish letters Å å, Ä ä, Ö ö

... // original message cut for clarity

Do I have to generate these 3 keypress events with native programming
or is there a way to do this in Java??

Regards Linus Sylvén

I would suggest to try a sequence like (I just triied it and it works):
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_NUMPAD1);
robot.keyRelease(KeyEvent.VK_NUMPAD1);
robot.keyPress(KeyEvent.VK_NUMPAD4);
robot.keyRelease(KeyEvent.VK_NUMPAD4);
robot.keyPress(KeyEvent.VK_NUMPAD3);
robot.keyRelease(KeyEvent.VK_NUMPAD3);
robot.keyRelease(KeyEvent.VK_ALT);

Cause when you press ALT+143 (numbers from the numeric pad), it displays
the 'ascii' character associated to '143', which is 'Å'. You can play
around 143 to find all the characters you need.
Do not rely on the standard ASCII table or in the Micro$oft Office
'Insert Symbol' decimal values. There might be some document somewhere
to find the whole table of the ALT+xxx characters, but I dunno where.
 
L

Linus Sylv?n

oh thanks that's a brilliant 'workaround' , it works just fine and
will do in my application.

This ALT 'some ASCII number' ALT trick is one of the first tricks I
learned with computers and I totally forgot about it.

Its amazing how hard it can be to find a solution if one keeps staring
at an other direction.

Thanks again.

Linus
 
Joined
Jun 3, 2009
Messages
1
Reaction score
0
Hi, I know this is an old post but this might help others.

You don´t need to use native C-code to make a Java Virtual Keyboard. I did the following:

this.setAlwaysOnTop(true);
this.setFocusable(false);
this.setFocusableWindowState(false);

To get ÅÄÖ you can use:

Å (only Linux, catch IllegalArgumentException and use the ALT+143 and ALT+134 method)
robot.keyPress(KeyEvent.VK_DEAD_ABOVERING);
robot.keyRelease(KeyEvent.VK_DEAD_ABOVERING);


Ä (Linux and Windows)
robot.keyPress(KeyEvent.VK_DEAD_DIAERESIS);
robot.keyRelease(KeyEvent.VK_DEAD_DIAERESIS);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);

Ö (Linux and Windows)
robot.keyPress(KeyEvent.VK_DEAD_DIAERESIS);
robot.keyRelease(KeyEvent.VK_DEAD_DIAERESIS);
robot.keyPress(KeyEvent.VK_O);
robot.keyRelease(KeyEvent.VK_O);

Hope this will help someone.

/Henrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top