Web APIs

KeyboardEvent.key

Try the free JavaScript compiler

Interpreted key value, taking keyboard layout and modifiers into account.

Formal Syntax & Structure

javascript syntaxjavascript
event.key

Return Value

string

Interpreted key.

Working Example

Example Snippetjavascript
const b=document.createElement("button");b.addEventListener("keydown",e=>console.log(e.key,e.code));b.dispatchEvent(new KeyboardEvent("keydown",{key:"a",code:"KeyQ"}));
JavaScript Reference