473,243 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,243 software developers and data experts.

C# KeyEventArgs - how to quickly determine if letter/number presse

Is there a way to quickly determine if the key pressed was from 'A'-'Z' or
'0'-'9' range?

I really don't like to write switch with every Keys.A, Keys.B, etc key listed

Paul
Feb 7 '07 #1
3 17729
Why don't you convert the pressed key into ASCII representation and then
verify if it matches?

--
Regards,
Robson Siqueira
Enterprise Architect
"panpawel" <pa******@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or
'0'-'9' range?

I really don't like to write switch with every Keys.A, Keys.B, etc key
listed

Paul

Feb 7 '07 #2
Thanks, but to do that I need to get the Char pressed. The pressed key is an
enumerated type Keys (from KeyEventArgs). I could not find a method to
convert it to Char.

Help, please...
"Robson Siqueira" wrote:
Why don't you convert the pressed key into ASCII representation and then
verify if it matches?

--
Regards,
Robson Siqueira
Enterprise Architect
"panpawel" <pa******@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or
'0'-'9' range?

I really don't like to write switch with every Keys.A, Keys.B, etc key
listed

Paul


Feb 8 '07 #3
OK, here is how I did it:

if ( ( ( e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z ) ||
( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 ) ||
( e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 ) )

However that works on the assumption than Keys enumeration of A-Z and 0-9
are in the continuous range, which makes sense but is not spelled out
anywhere...

"panpawel" wrote:
Thanks, but to do that I need to get the Char pressed. The pressed key is an
enumerated type Keys (from KeyEventArgs). I could not find a method to
convert it to Char.

Help, please...
"Robson Siqueira" wrote:
Why don't you convert the pressed key into ASCII representation and then
verify if it matches?

--
Regards,
Robson Siqueira
Enterprise Architect
"panpawel" <pa******@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or
'0'-'9' range?
>
I really don't like to write switch with every Keys.A, Keys.B, etc key
listed
>
Paul
Feb 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mh | last post by:
Hi Folks- I'm trying to do a simple emulation of unix "locate" functionality in python for windows. Problem is I don't want to crawl/index optical drives. Do any of the windows people out...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
1
by: Chaoxiang | last post by:
the KeyEventArgs.KeyCode is readonly, so I want to override it. How to do it? I create a class, public class ExteKeyEventArgs : KeyEventArgs { ExteKeyEventArgs(Keys keys) } but it has a...
3
by: KSC | last post by:
Hello, Is there a way to programmatically determine if a directory is shared and if so, what the sharename is? It seems a simple question, but I have been searching and not found the...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
2
by: gazz | last post by:
Hi, Please could someone shed some light on this as I am really struggling to understand how to do this. Given a word entered into a window.prompt EG "forum", how do I create a script to...
9
by: Ulterior | last post by:
Hi, everyone, I have a simple problem, which bothers me for some while. I will try to explain it - There is some string, whith different letters in it. Is it possible to analyse this string...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.