Re: Converting non-control ASCII chars to KeyEvent key codes?



On Dec 17, 7:56 pm, "John B. Matthews" <nos...@xxxxxxxxxx> wrote:
In article
<bf9c1fba-7a1f-4b3f-a507-56e02ab04...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,



 softwarepearls_com <i...@xxxxxxxxxxxxxxxxxx> wrote:
On Dec 16, 8:09 pm, Mark Space <marksp...@xxxxxxxxxxxxx> wrote:
softwarepearls_com wrote:
Is there any simple way?

Looking at KeyEvent.VK_A to keyEvent.VK_Z's contiguous range lets us
map letters quite easily, but I'm after broader input, namely all non-
control ASCII characters.

I'm after an API like

public int toKeyEventKeyCode(byte asciiChar)

I haven't tried this but KeyEvent does take a char in two of its
constructors....

Sure.. but if you check the source, you'll see that the char is simply
stored, and nowhere does it form the input for some kind of logic that
I'm after (in KeyEvent that is).

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.

Actually, the API that I'm after would need to return an array of key
codes because some chars would map to more than a single keycode. E.g.
all capitals would map to VK_SHIFT plus the letter key code.

Would it help to explain what you're trying to accomplish?

--
John B. Matthews
trashgod at gmail dot comhttp://home.roadrunner.com/~jbmatthews/

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
&lt;keycode&gt;,&lt;keycode&gt;,&lt;keycode&gt;,...&lt;EOL&gt;
* <LI> P &lt;keycode&gt;&lt;EOL&gt;
* <LI> R &lt;keycode&gt;&lt;EOL&gt;
* <LI> S &lt;string&gt;&lt;EOL&gt;
* <LI> E&lt;EOL&gt;
* </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>
* &lt;keycode&gt; is a valid, integer key code (as defined by {@link
KeyEvent}),
* &lt;string&gt; is any String of characters that should be
translated into a sequence of
* Press/Release events. &lt;EOL&gt; 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..
.



Relevant Pages

  • Re: Musings on a holiday weekend
    ... This was the last year of the governorship of the then governor whatever. ... The keyboard would have enough memory to ... so the mix of characters ... control keys to select the keymap you need. ...
    (bit.listserv.ibm-main)
  • RE: Musings on a holiday weekend
    ... I've been toying with ideas around the future of z/OS (if there is such ... The keyboard would have enough memory to ... so the mix of characters ... control keys to select the keymap you need. ...
    (bit.listserv.ibm-main)
  • Re: suggestions for new module name
    ... Several metrics of effort are used. ... > This module is useful for determining which keyboard layout is more ... That means that accented characters, unicode, etc. are not ...
    (comp.lang.perl.modules)
  • Re: special characters, ie spanish accents
    ... If you do a web search on keyboard layouts and go to the ... characters instead of 30 is a different matter. ... There is also an English International layout that gives you many of the ... dead keys and you still see the original layout for English keyboards. ...
    (freebsd-questions)
  • Re: Fast UTF-8 strlen function
    ... numpad" sequence to work with UNICODE characters for Windows (for those who ... The best means is to install a bunch of "virtual keyboards"...on XP, ... you can install "input languages" and "virtual ... button...select the language and then select the keyboard (note that there ...
    (alt.lang.asm)