473,574 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ 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 34226
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******** ********@TK2MSF TNGP09.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.RControlKe y) 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******** ********@TK2MSF TNGP09.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
3900
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 different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and...
1
20749
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 ="onBlurCurrencyCheck(event, 'x')""> Works very well with IE, but window.event and maybe window.event.keycode too seems to be missing form firefox. Is there a...
6
14899
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 keypress() {
4
21236
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 are different on a Danish keyboard layout. "-" returns 45 and 189 respectively. Etc. (The input-field in the sample code below displays the right...
2
5024
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 (Control.ModifierKeys == Keys.Tab), checked for it by MessageBox.Show((e.KeyValue).ToString()); (it responded to every key I tried except for Tab)),
3
26340
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 = e.keyCode; } alert('You pressed the key: ' + String.fromCharCode(key));
4
61140
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 this. 's BD
1
2229
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? Is there a way to store a Keys enum value as a key, and enumerate throug each key. this way i can compare which key it is, and assign it to the...
1
2845
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: 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...
0
7738
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...
0
8077
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. ...
1
7828
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...
0
8113
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...
0
6476
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...
1
5634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3755
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...
0
3765
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.