Languages
[Edit]
EN

JavaScript - detect when ctrl key was pressed

0 points
Created by:
Rubi-Reyna
677

In this article, we would like to show you how to detect when the CTRL key was pressed using JavaScript​​​​​.

Quick solution:

 

1. Practical example

Edit

In this example, we use ctrlKey property to detect if the Ctrl key was pressed.

2. Ctrl + another key

Edit

In this example, we present how to detect when q key was pressed while holding the Ctrl key.

3. Ctrl + mouse click

Edit

In this example, we present how to detect when the left mouse button was clicked while holding the Ctrl key.

See also

Edit
  1. JavaScript - keyboard events

  2. JavaScript - mouse events

References

Edit
  1. KeyboardEvent.ctrlKey - Web APIs | MDN
  2. Document: keydown event - Web APIs | MDN

Alternative titles

  1. JavaScript - detect when ctrl key was pressed with another key
  2. JavaScript - detect when key was pressed while holding ctrl key
  3. JavaScript - detect when control key was pressed
  4. JavaScript - detect when control key was pressed with another key
  5. JavaScript - detect when key was pressed while holding control key
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join