Search.../

key

Gets a string representation of the key that was pressed.

Description

For keys representing a printable character, the key property gets a Unicode character string containing the printable representation of the key that was pressed. This does not necessarily correspond to what is printed on the physical key since the user could have changed the keyboard layout.

For keys that have no printable representation, a string indicating the key's purpose is returned. Some examples are:

  • "Backspace"
  • "Enter"
  • "F1"
  • "Escape"
  • "Tab"

Type:

stringRead Only

Was this helpful?

Gets the keyboard event's key property when the a key is pressed

Copy Code
1$w("#myElement").onKeyPress( (event) => {
2 let key = event.key; // "A"
3} );
Gets all of the keyboard event's properties

This example gets the properties of a keyboard event fired when the Shift and a keys are pressed.

Copy Code
1$w("#myElement").onKeyPress( (event) => {
2 let key = event.key; // "A"
3 let shift = event.shiftKey; // true
4 let meta = event.metaKey; // false
5 let alt = event.altKey; // false
6 let ctrl = event.ctrlKey; // false
7 let value = event.target.value; // string value of text inside "#myElement" before the last KeyPress event
8} );
9