What is KeyValue (in contrast to KeyCode)?

P

Peter Anthony

This is a perfect example of how some information slips through the crack in
MSDN2. There is NO explanation of what KeyValue is in MSDN2!! Sure, it has a
page on it, here it is:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.keyeventargs.keyvalue.aspx

But all it says is that it is the ' The integer representation of the
KeyCode property.' But KeyCode is of data type Keys which is an enum, so its
ALREADY an integer!

Further, this is how MSDN2's example code shows us how to 'use' it (also on
above page):

messageBoxVB.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue) ;
messageBoxVB.AppendLine() ;

Great. I can display it in a message box. How does that at all tell me HOW
TO USE IT? Or even WHAT IT IS FOR?

Even worse is 'KeyData'. For which the description is:

" A Keys representing the key code for the key that was pressed, combined
with modifier flags that indicate which combination of CTRL, SHIFT, and ALT
keys was pressed at the same time."

[ from
http://msdn2.microsoft.com/en-us/library/system.windows.forms.keyeventargs.keydata.aspx ]

But 'Keys' is not a structure, it is an enum!!!! Again, from this
description I have no idea how to USE it. Oh wait, it says this is how to
use it:

messageBoxVB.AppendFormat("{0} = {1}", "KeyData", e.KeyData) ;
messageBoxVB.AppendLine() ;

Yup, that makes everything so perfectly clear, now that I know I can display
its value in a message box too! Yeah!!! [sarcasm off]

While I do feel MSDN2 is getting better (or else I'm just getting use to
it), this kind of stuff is very frustrating. All I wanted to find is a way
to get the ASCII 'char' of the key hit, and I am finding all I have to work
with is KeyData, KeyCode, and KeyValue, which MSDN2 seems to indicate are
ALL THE SAME, and return the KeyCODE. But nowhere can I find how to get the
ASCII value (the 'char' value).

That is, I want to get a '7' whether the numpad or normal numeric key for
'7' are hit, I don't want these to be two separate cases. Nor do I want to
have to know if the SHIFT key is pressed to get '&' instead of '7'. I want
the ASCII value, not have to parse the dang keyboard to figure out what the
ASCII value for the key that was pressed is...

I MUST be missing something, this has to be pretty easy!
 
P

Peter Anthony

OK. Found it. It is in KeyPressArgs. Wish they could have actually mentioned
this on the KeyDown and KeyUp description pages.

MSDN2 is a dang PUZZLE! lol
 

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