shiftKey The Event property

shiftKey Event attribute The event object

Definitions and usages

The shiftKey event property returns a Boolean value indicating whether the SHIFT key is pressed and held when an event occurs.

Grammar

event.shiftKey=true|false|1|0

The following example indicates whether the "SHIFT" key is held down when the mouse button is clicked:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool在线教程(w3cschool.cn)</title>
<script>
function isKeyPressed(event){
if (event.shiftKey==1){
Alert ("Shift button is pressed!");
}
else{
Alert ("Shift" is not pressed! ");
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">

<p>点击该段落,弹窗会提示是否按下 shift 键。</p>

</body>
</html>

Try it out . . .


shiftKey Event attribute The event object