PC Review


Reply
Thread Tools Rate Thread

Detecting a key from the ASCII character set

 
 
=?Utf-8?B?UmF5IE1pdGNoZWxs?=
Guest
Posts: n/a
 
      23rd Apr 2007
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
 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      23rd Apr 2007
"Ray Mitchell" <RayMitchell_NOSPAM_@MeanOldTeacher.com> wrote in message
news:AEC7F7A3-B3FF-4579-9B2E-(E-Mail Removed)...
> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ascii to character Gautam Microsoft Excel Programming 2 19th Apr 2007 09:56 AM
ascii or windows character herbzee Windows XP Help 1 31st Jul 2006 02:48 PM
ASCII character problems Edw. Peach Windows XP Help 3 27th Dec 2004 04:51 PM
Get Ascii value of a character Sammut Microsoft C# .NET 1 28th Jul 2004 06:49 AM
GEt the Ascii value of a Character Sammut Microsoft C# .NET 1 28th Jul 2004 02:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:44 AM.