Difference between keyup(), keydown() and keypress()

Asked

Viewed 16,196 times

13

I’d like to know the difference between keyup(), keydown() and keypress(), in my opinion I think they do the same thing, but what is the purpose of each?

Performance improvement for each type?

1 answer

25


They don’t really do the same thing.

keyup(): the event occurs when the key returns to the original position on the keyboard (i.e. when you release it).

keydown(): the event occurs when the key is pressed. The event repeats while the key is pressed (except for the keys Ctrl, Alt and Shift).

keypress(): the event occurs when the key is pressed. The event repeats while the key is pressed (except for the keys Ctrl, Alt and Shift).

The difference between keydown() and keypress() is that the second is not captured when the keys Ctrl, Alt or Shift are pressed.

  • 1

    If they are used to capture keys, only the keypress is case-sensitive.

  • Thanks a lot, tmj!

  • Boleta show.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.