Detecting a key from the ASCII character set

G

Guest

Hello,

I have a KeyDown event in which I would like to determine if the current key
is a standard character (i.e., from the ASCII character set). In C I would
use something like the isascii finction for this, but I realize the key
values produced by the Keys enumeration are not simply the ASCII value of the
keys. I've found references to the IsInputKey method but I can't fiture out
how it is used (or if it should be used) for this purpose in my KeyDown event
handler. My only other thought is to individually test the value of the
KeyCode against each key value I am willing to accept, but this is much to
brutal and I'm sure, inappropriate.

Thanks,
Ray
 
P

Peter Duniho

Ray Mitchell said:
Hello,

I have a KeyDown event in which I would like to determine if the current
key
is a standard character (i.e., from the ASCII character set). [...]
My only other thought is to individually test the value of the
KeyCode against each key value I am willing to accept, but this is much to
brutal and I'm sure, inappropriate.

The KeyDown event doesn't tell you much at all about the character being
entered. It tells you which physical key is being pushed. This can be
converted to a specific character code, of course, but the event is really
more for situations where the specific key being pushed is interesting to
you.

If you want a more character-oriented input scheme, you may want to consider
looking at the KeyPress event instead. That will return ASCII values, which
you can then check for inclusion as a "standard character" (however you
choose to define that).

The IsInputKey() method is not really relevant, I think. It is more useful
if you already have code that determines whether the KeyDown event
corresponds to a key that would not normally be considered an input key, but
which you would like to for some reason. You can override it and then
return true if you don't want the key preprocessed (for example, if you have
a text-editing control and you want tab characters to be entered into it
instead of having the focus changed).

Pete
 

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

Top