CKTIS / JavaScript
KeyboardEvent fields: key meaning, position, and state
Distinguish a key's value from its physical position, and inspect repetition, Shift state, and text composition. These KeyboardEvent fields help handle shortcuts without confusing keyboard layout with text input.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
event.key; event.code; event.repeat; event.shiftKey; event.isComposingKeyboardEvent describes keyboard events such as keydown and keyup. The five properties covered here (key, code, repeat, shiftKey, and isComposing) are read-only, but some properties inherited from Event, such as cancelBubble, are writable. KeyboardEvent.key is a string identifying the key's meaning, accounting for layout and modifiers, such as "z", "Z", or "Enter". KeyboardEvent.code is a string identifying the key's physical position regardless of layout: "KeyY" can accompany key: "Z" on a QWERTZ keyboard. Use key for key meaning and code for position-based controls.
KeyboardEvent.repeat is a boolean: true indicates automatic repetition of a held key, not a repetition count. In a keydown handler, if (event.repeat) return; can skip repeated actions. KeyboardEvent.shiftKey indicates whether Shift was active when the event occurred; it does not mean the event itself concerns Shift. On a Shift keydown, the value is true; on a Shift keyup, it can still be true if the other Shift key is held down.
KeyboardEvent.isComposing is a boolean indicating an event between compositionstart and compositionend, for example during IME text composition. Skipping shortcuts when it is true reduces interference with composition, but does not detect every IME boundary case: it can be false at the start or end of composition. Keyboard events do not replace the input event for tracking text changes.
These are browser Web APIs, not features of a particular ECMAScript edition; Node 24 in the repository does not establish their availability. Check each property's compatibility against target browsers; MDN marks repeat as Baseline 2025, which does not guarantee support in older versions. The example constructs a synthetic event with explicit values: it checks field access, not real key presses or IME behavior.
Examples
(() => {
const event = new KeyboardEvent("keydown", {
key: "Z",
code: "KeyY",
repeat: true,
shiftKey: true,
isComposing: false
});
const { key, code, repeat, shiftKey, isComposing } = event;
console.log(JSON.stringify({ key, code, repeat, shiftKey, isComposing }));
})();Result
{"key":"Z","code":"KeyY","repeat":true,"shiftKey":true,"isComposing":false}The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.