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 は読み取り専用のプロパティで、イベント発生時に alt キー(macOS では Option または )が押されたか (true) または押されていないか (false) を示す論理値です。

論理値です。

html
<!doctype html>
<html lang="ja">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>altKey の例</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>
      ALT キーを押したまま、または押さずに、任意の文字キーを押してください。<br />
      また、 SHIFT キーと ALT キーを同時に使用することもできます。
    </p>
  </body>
</html>

仕様書

Specification
UI Events
# dom-keyboardevent-altkey

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
altKey

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報