Back to Content

KeyboardEvent: altKey property

files/en-us/web/api/keyboardevent/altkey/index.md

latest850 B
Original Source

{{APIRef("UI Events")}}

The KeyboardEvent.altKey read-only property is a boolean value that indicates if the <kbd>alt</kbd> key (<kbd>Option</kbd> or <kbd></kbd> on macOS) was pressed (true) or not (false) when the event occurred.

Value

A boolean value.

Examples

html
<p>
  Press any character key, with or without holding down the ALT key.

  You can also use the SHIFT key together with the ALT key.
</p>
<pre id="output"></pre>
js
const output = document.getElementById("output");

function showChar(e) {
  output.textContent = `Key KeyDown: "${e.key}"
ALT key KeyDown: ${e.altKey}
`;
}

document.addEventListener("keydown", showChar);

{{EmbedLiveSample("examples", "", "400")}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{ domxref("KeyboardEvent") }}