views:

74

answers:

2

What is the difference between these three events? Upon googling I found that

The KeyDown event is triggered when the user presses a Key.

The KeyUp event is triggered when the user releases a Key.

The KeyPress event is triggered when the user presses & releases a Key. (onKeyDown followed by onKeyUp)

I understand the first two, but isn't KeyPress the same as KeyUp? (or is it possible to release a key(keyup) without pressing(keydown) it?)

This is a bit confusing, can someone clear this up for me?

+1  A: 

Check here: http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key-Events.aspx

From that link:

In theory, the keydown and keyup events represent keys being pressed or released, while the keypress event represents a character being typed. The implementation of the theory is not same in all browsers.

dcp
Thanks for the link, It was very helpful! :)
instantsetsuna
+1  A: 

KeyPress, KeyUp and KeyDown are analagous to, respectively, Click, MouseUp, and MouseDown.

The *Down happens first, the *Press happens second (when text is entered), and the *Up happens last (when text input is complete).

The exception is webkit, which has an extra event in there:

keydown
keypress
textInput     
keyup
Robusto
So, Is KeyPress just an extra event that's b/w KeyDown and TextInput? How is it(KeyPress) generally used by developers?
instantsetsuna

related questions