Javascript | MouseEvent ctrlKey Property
The mouseEvent ctrlKey property is used to define whether the ctrl key is pressed or not. It is a boolean value. When ctrl key is pressed then on click of the mouse buttons it returns true and if it is not pressed then it returns false.
Syntax:
event.ctrlKey
Return Value: It returns a boolean value indicating whether ctrl key is pressed or not.
- true: it indicates ctrl key is pressed.
- false: it indicates ctrl key is not pressed.
Example :
<!DOCTYPE html> <html> <head> <title>JavaScript Mouse Event</title> </head> <body style = "text-align:center;"> <h1 style = "color:green;"> GeeksforGeeks </h1> <h2> mouseEvent ctrlKey Property </h2> <button onclick="geek (event);">Get Ctrl key state!</button> <script> function geek (event) { if (event.ctrlKey) { alert ("Ctrl key is pressed."); } else { alert ("Ctrl key is not pressed."); } } </script> </body> </html> |
Output:
Clicking button (ctrl key is not pressed):

Clicking button (ctrl key is pressed):

Supported Browsers: The browser supported by ctrlKey property are listed below:
- Apple Safari
- Google Chrome
- Firefox
- Opera
- Internet Explorer
Recommended Posts:
- Javascript | MouseEvent which Property
- Javascript | MouseEvent altKey Property
- JavaScript | MouseEvent shiftKey Property
- JavaScript | MouseEvent Button Property
- HTML | DOM TouchEvent ctrlKey Property
- Javascript | MouseEvent getModifierState() Method
- HTML | DOM MouseEvent offsetY Property
- HTML | DOM MouseEvent buttons Property
- HTML | DOM MouseEvent screenX Property
- HTML | DOM MouseEvent screenY Property
- HTML | DOM MouseEvent relatedTarget Property
- HTML | DOM MouseEvent offsetX Property
- HTML | DOM MouseEvent clientX Property
- HTML | DOM MouseEvent pageX Property
- HTML | DOM MouseEvent clientY Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



