473,473 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

KeyCode, KeyValue and KeyData

Could you tell me witch is the difference between keycode, keyvalue and
keydata in a keydown event?
keyvalue is always the ascii code?
thank you
Nov 28 '05 #1
2 34179
Hi,

Yes , in is the one you probably use, KeyData return an enumeration (
Key )

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alberto" <al*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you tell me witch is the difference between keycode, keyvalue and
keydata in a keydown event?
keyvalue is always the ascii code?
thank you

Nov 28 '05 #2
Alberto,

There are KeyUp, KeyDown and KeyPress event. Only the KeyPress event
supplies the character code. I don't say ASCII because this code depends on
the current language settings; even one code can be generated as a result of
pressing a sequence of keys. Even in the simplest cases with English
language settings there is no 1:1 mapping between keys and character codes
e.g. key A produces ASCII for 'a' or key A produces ASCII for 'A' if
cpaslock is on or shift is pressed or 'a' of both capslock is on and shift
is pressed, etc. Even more there are keys that don't produce ASCII codes -
ctrl, alt, shift, F1, F2., Fx, windows keys, etc

As you can see keyboards cannot generate character codes they rather
generates special codes that gives 1:1 mapping between key and some code.
Windows internally uses special codes called VK_* (virtual) codes. They are
not related to any language and represent the keys themselves. Thus VK for
the key A is the same regardless whether shift is pressed or capslock is on.
In .NET the values of those keyboards key codes are the values of the Kyes
enumeration. Last time I checked they were the same as Windows VK codes.

Anyways all data that comes along with KeyUp and KeyDown are not ASCII
codes, but rather some form of *Keys* enum values or combination between
them. It just happens that the codes for letter keys match the ASCII codes.

One more thing related to key codes. There are two types of keys - regular
keys and modifier keys. Regular keys are all the keys that have some meaning
when pressed alone. Modifier keys are SHIFT, CTRL and ALT that normally is
pressed in combination with other keys to change their normal behavior. Keys
enumeration has two codes for modifier keys. One is to handle the key itself
(e.g Keys.ControlKey, KeysLCotnrolKey and Keys.RControlKey) and the other is
modifier code (e.g. Keys.Control). The modifier code is a bit value that can
be combined with regular key codes in order to produce a new code that
contains information about the key itself as well as all pressed modifier
keys at the moment of event generation.

KeyData - a value that is bitwise OR combination between one Key enum value
and 0 or more *Keys* modifier values if any of the modifier keys has been
pressed at the moment of event generation. Since this value might be a
result of bitwise OR operation it might not have corresponding member in the
Keys enum.

KeyCode - *Keys* enum value that represents pressed or released key without
with all modifier keys information stripped out. This property always
contains value form the Keys enum and is the key part of the KeyData.

Modifiers - only the modifier part of the KeyData.

KeyValue - the same as KeyData, but converted to an integer value. It is
meant to be used probably when the value needs to be passed to a unmanaged
method via PInvoke.

And there are couple of Boolean properties for easy checking the modifier
keys.


HTH

Stoitcho Goutsev (100) [C# MVP]
There are KeyUp, KeyDown and KeyPress event. Only KeyPress event suplies the
the character code. I don't say ASCII code because for non english keyboards
setting
"Alberto" <al*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you tell me witch is the difference between keycode, keyvalue and
keydata in a keydown event?
keyvalue is always the ascii code?
thank you

Nov 28 '05 #3

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

Similar topics

6
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
4
by: Thomas Christensen | last post by:
I'm trying to figure out what key the user pressed using a Danish keyboard layout. charCodeAt returns the correct number, but event.keyCode returns a wrong number, when using one of the keys that...
2
by: melanieab | last post by:
Hi, Just checking to see if there's anything I can possibly do to allow for the recognition of the Tab key being pressed. On the KeyDown event I've tried: if (e.KeyCode == Keys.Tab), if...
3
by: Pugi! | last post by:
I got this (piece of) script from 'DHTML Utopia - Modern Webdesign - Using Javascript & DOM'. function aKeyWasPressed(e) { if (window.event) { var key = window.event.keyCode; } else { var key...
4
by: BD | last post by:
Hi, I need to convert a KeyCode from event KeyDown to a string. For example Keys.Decimal that's 110 to ".", but it converts to char 'n' that's the code ascii of 110. I'm a little confuse with...
1
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi all, Ive ran into a problem where i convertted the keyData to a string and stored it in the database. But am unable to convert it back to a KeyData for comparisn. Is there a way to do that? ...
1
by: Peter Anthony | last post by:
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: ...
0
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,...
0
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...
0
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,...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.