ctrlKeyEvent Property
Event Object
Definition and Usage
The ctrlKey event property returns a Boolean value indicating whether the Ctrl key was pressed and held down when the event occurred.
Syntax
event.ctrlKey=true|false|1|0
Example
Example
The following example indicates whether the "CTRL" key was held down when the mouse button was clicked:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function isKeyPressed(event){
if (event.ctrlKey==1){
alert("CTRL key was pressed!");
}else{
alert("CTRL key was not pressed!");
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document. An alert box will tell you whether you pressed the CTRL key.</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function isKeyPressed(event){
if (event.ctrlKey==1){
alert("CTRL key was pressed!");
}else{
alert("CTRL key was not pressed!");
}
}
</script>
</head>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document. An alert box will tell you whether you pressed the CTRL key.</p>
</body>
</html>
Try it Yourself »
Event Object Other Extensions