473,666 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17821
Why don't you convert the pressed key into ASCII representation and then
verify if it matches?

--
Regards,
Robson Siqueira
Enterprise Architect
"panpawel" <pa******@discu ssions.microsof t.comwrote in message
news:5F******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.comwrote in message
news:5F******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.comwrote in message
news:5F******** *************** ***********@mic rosoft.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
3473
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 there know how I can determine: 1. How many drives are on the system? (I could just iterate over the alphabet os.path.exists("%s:\\"%letter) ... is there a "windows" way of
3
2271
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 typedef unsigned long int uint32; /* 32 bits */ // Up to 36 request flags, so this will take up to 3
9
19522
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: How do I determine how many characters I can get on a line Question 3: How do I determine how many lines I can get on a page. Assume no margins Question 4: Does their exist some kind of refernce table that will equate a font with chars/line and...
1
2700
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 error, the error said, the method KeyEventArgs has not over ride(error CS1501).
3
6808
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 answer... Thanks in advance!
4
2389
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 of making a case statement with 26 options, is there a more streamlined way to get an integer between 1-26 translated into one of the letters?
2
1575
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 determine the postion of a letter by entering a number no longer than the string and output that letter to screen. I have completed the prompting and selection the bold section below is where I become stuck. Any help would be appreciated greatly. EG ...
9
2234
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 and the reffer to it knowing that it has some certain letters in it using only some integer value?
11
7690
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
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.