A KeyEvent holds information about which key on a keyboard was pressed,
released or typed. To translate a keyCode to a Unicode character, you
need the modifiers, as is done by getKeyChar() for KEY_TYPED events.
Indeed, the constructor throws an exception for certain meaningless
combinations.
IUUC, you want the converse: the KeyEvent that would be generated for a
given character. Sadly, there's nothing named getGlyphOnKeyCap(); I
guess a keyboard full of little LCDs would be a might pricey and perhaps
too fragile.
Would it help to explain what you're trying to accomplish?
Sure, no problem since this bit is going to be OSS-ed.
I've written a class KeyboardRemoteControl which .. hang on.. copy-
paste from javadocs:
/
**********************************************************************************************
* Miniature TCP-based server giving arbitrary external programs
access to a {@link Robot}
* instance's native keyboard event injecting capabilities.
* <P>
* You can embed a {@link KeyboardRemoteControl} into any application
(or plugin) to allow
* primitive keyboard-driven "scripting" of your application. For
applications which provide
* good support for keyboard shortcuts (eg for menu item actions),
this means you can expose
* most of your application's functionality via this back door.
* <P>
* The TCP port used to publish the service is configurable (any port
within 1024..65535
* range).
* <P>
* The {@link KeyboardRemoteControl} protocol is very simple, and
consists only of the
* following ASCII commands sent to the server.
* <UL>
* <LI> C
<keycode>,<keycode>,<keycode>,...<EOL>
* <LI> P <keycode><EOL>
* <LI> R <keycode><EOL>
* <LI> S <string><EOL>
* <LI> E<EOL>
* </UL>
* C = Chord (multiple keys pressed simultaneously), eg to send CTRL-
C<BR>
* P = Press key<BR>
* R = Release key<BR>
* S = String, eg to send a string of plain characters like a
filename<BR>
* E = ENTER key
* <P>
* <keycode> is a valid, integer key code (as defined by {@link
KeyEvent}),
* <string> is any String of characters that should be
translated into a sequence of
* Press/Release events. <EOL> is either LF, CR, or a CR-LF
pair.
* <P>
* The server never sends back any information to the connecting
client (not to welcome a
* client, nor to acknowledge received commands).
*
* @author Software Pearls BVBA
*********************************************************************************************/
The only thing not yet workig is the S packet, ie being able to send a
whole String of characters to be fed to the Robot instance. Getting
that to work requires the OT requirements..