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 July 2015.
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 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
shiftKey |
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.