Can anyone tell me the difference between the KeyDown
event, the KeyPress
event and the KeyUp
event? I checked the msdn site and it do
In addition to the other answers:
When trying to figure to which of these events you should hookup your action, mind that the KeyDown
event will be fired multiple times while the key is held down. Sometimes you want this behavior, sometimes not. Based on that I suggest the following usage (based on my experience):
(Order in which events are fired)
KeyDown
Occurs: When key is pressed and while held down
Usage: Perform action immediately on button press or even multiple times when held down
Example: Moving cursor with arrow keys
.
KeyPress
Occurs: Character key is pressed (Higher level event)
Usage: Anything typing related
Example: Handle textbox input
.
KeyUp
Occurs: Key is released
Usage: Perform critical action which should only occur once per keystroke
Example: Write data to file