Qcom
Qcom

Reputation: 19203

jQuery kepress detection on left, right arrows and space bar

I'm trying to use a little jQuery here to detect which keys are being pressed.

I've a lot about trying to use functions to detect ASCII codes and such to see which keys are being pressed, but I'm a little confused.

Also, what's the difference between keyUp, keyDown and keypress?

Upvotes: 0

Views: 1448

Answers (2)

BoltClock
BoltClock

Reputation: 724252

  1. A key down event is fired when a key is pressed down.
  2. A key press event is fired for every character that is actually typed if a user continues to hold down the key to let a character repeat.
  3. A key up event is fired when the key is released.

Upvotes: 2

bryan.taylor
bryan.taylor

Reputation: 584

keydown:
Fires when the user depresses a key. It repeats while the user keeps the key depressed.

keypress:
Fires when an actual character is being inserted in, for instance, a text input. It repeats while the user keeps the key depressed. Not supported by Safari iPhone.

keyup:
Fires when the user releases a key, after the default action of that key has been performed.

From: http://www.quirksmode.org/dom/events/keys.html

Upvotes: 3

Related Questions