JavaScript Keyboard Events

In this article, you will learn about various JavaScript keyboard events.

There are events from keyboard also,
Those events are

  • Keydown
  • Keyup
  • Keypress

The key is the character in the language and keycode is the code for the character.
For example.
Event.key = Shift means it is referring to Shift key.
Event.keyCode = 16 referring to code of key(the shift).

The legacy keyboard property are

  • keyCode
  • shiftKey
  • ctrlKey
  • altKey

Keypress event is not deprecated.

Keyboard Layout

There are many keyboards in different languages. QWERTY is the most popular.

QWERTY keyboard
QWERTY keyboard

QWERTZ is used in Germany.

DVORAK is an alternative to QWERTY.
Keyboards have same layout and they can be rearranged or adjusted. This is called the Mechanical Layout.The regional layouts have

  1. Functional layout – software(driver) that maps hardware keys to characters.
  2. Visual layout – physical characters printed on the keyboard keys.

Keyboard events are keyup, keydown and keypress. The keypress event is character events. The keyboard events have legacy properties

  • keyCode
  • charCode
  • which

The new api solves lot of problem with the keyboard.

Keyboard.key = gives the character for key or descriptive key such as backspace.
Keyboard.code = gives the physical code of the key.
Both are independent of each other. There is no existing keyboard with all the keys.

Please support us by disabling your adblocker or whitelist this site from your adblocker. Thanks!

turn of adblocker imag