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.
<span style="color:#e71111" class="tadv-color">Event.key = Shift</span> means it is referring to Shift key.
<span style="color:#e9250b" class="tadv-color">Event.keyCode = 16 </span>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.


Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.