Latest web development tutorials

shiftKey Event Properties

Event Object Reference Event objects

Definition and Usage

shiftKey Events property returns a Boolean value that indicates when an event occurs, "SHIFT" key is pressed and hold.

grammar

event.shiftKey=true|false|1|0

Examples

Examples

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function isKeyPressed(event){
    if (event.shiftKey==1){
        alert(" shift 键被按下!");
    }
    else{
        alert(" shift 键没被按下!");
    }
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">

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

</body>
</html>

try it"


Event Object Reference Event objects