KeyboardEvent.altKey

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

Value

A boolean value.

Examples

<!doctype HTML>
<html lang="en-US">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>altKey example</title>

<script>

function showChar(e){
  alert(
    "Key KeyDown: " + String.fromCharCode(e.charCode) + "\n"
    + "charCode: " + e.charCode + "\n"
    + "ALT key KeyDown: " + e.altKey + "\n"
  );
}

</script>
</head>

<body onkeydown="showChar(event);">
<p>
Press any character key,
with or without holding down the ALT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>

Specifications

Specification
UI Events
# dom-keyboardevent-altkey

Browser compatibility

BCD tables only load in the browser

See also