KeyboardEvent: shiftKey プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
KeyboardEvent.shiftKey
は読み取り専用プロパティで、このイベントが発生したときに shift キーが押されていたか (true
) いなかったか (false
) を示す論理値を返します。
値
論理値です。
例
html
<html lang="ja"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <title>シフトキーの例</title> <script> function showChar(e) { alert( "押されたキー: " + String.fromCharCode(e.charCode) + "\n" + "charCode: " + e.charCode + "\n" + "SHIFT key pressed: " + e.shiftKey + "\n" + "ALT key pressed: " + e.altKey + "\n", ); } </script> </head> <body onkeypress="showChar(event);"> <p> SHIFT キーを押しながら、または押さずに、任意の文字キーを押してください。<br /> SHIFT キーと ALT キーを併用することもできます。 </p> </body> </html>
仕様書
Specification |
---|
UI Events> # dom-keyboardevent-shiftkey> |
ブラウザーの互換性
Loading…