KeyboardEvent key Property

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








googletag.cmd.push(function() googletag.display('div-gpt-ad-1422003450156-2'); );




KeyboardEvent key Property



❮ DOM Events
❮ KeyboardEvent




Example


Get the keyboard button that was pressed when a key event occured:



var x = event.key;

Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


The key property returns the identifier of the key that was pressed when a
key event occured.


Key identifiers are strings that identify keyboard buttons. The return value
of this property can be a string of:


  • A single character (like "a", "W", "4", "+" or "$")

  • A multicharacter (like "F1", "Enter", "HOME" or "CAPS LOCK")

Note: This property is read-only.


Tip: If you want to find out whether the "ALT", "CTRL",
"META" or "SHIFT" key was pressed when a key event occured, use the
altKey,
ctrlKey, metaKey or
shiftKey property.



Browser Support


The numbers in the table specify the first browser version that fully supports the property.














Property
key 51.0 9.0 23.0 Not supported 38.0






googletag.cmd.push(function() googletag.display('div-gpt-ad-1493883843099-0'); );





Syntax



event.key

Technical Details






Return Value:
A String, representing the pressed keyboard button.

Possible values:
  • A single character (like "a", "W", "4", "+" or "$")

  • A multicharacter (like "F1", "Enter", "HOME" or "CAPS LOCK")

Note: Returns undefined in Safari
DOM Version: DOM Level 3 Events

More Examples




Example


Alert some text if the user presses the "A" key:



var x = event.key;

// If the pressed keyboard button is "a" or "A" (using caps lock or shift), alert some text.

if (x == "a" || x == "A")
  alert ("You pressed the 'A' key!");


Try it Yourself »


Related Pages


HTML DOM reference: KeyboardEvent keyCode Property


HTML DOM reference: KeyboardEvent which Property


HTML DOM reference: KeyboardEvent charCode Property




❮ DOM Events
❮ KeyboardEvent


Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)