KeyboardEvent.altKey
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
KeyboardEvent.altKey
свойство только для чтения, возвращает Boolean
, если клавиша alt (Option или ⌥ на OS X) была нажата (true
) или не нажата (false
), когда событие произошло.
Синтаксис
var altKeyPressed = instanceOfKeyboardEvent.altKey
Пример
js
<html>
<head>
<title>altKey example</title>
<script type="text/javascript">
function showChar(e){
alert(
"Нажата клавиша: " + String.fromCharCode(e.charCode) + "\n"
+ "charCode: " + e.charCode + "\n"
+ "клавиша ALT нажата: " + e.altKey + "\n"
);
}
</script>
</head>
<body onkeypress="showChar(event);">
<p>
Нажмите любую клавишу с зажатой клавишей ALT или без неё<br />
Вы можете также использовать SHIFT вместе с ALT.
</p>
</body>
</html>
Спецификации
Specification |
---|
UI Events # dom-keyboardevent-altkey |
Совместимость с браузерами
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
altKey |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.