Guys, I need to track down the Ctrl key. I am tracking the window.onkeydown event. If the Ctrl key is pressed, then the variable __ctrl = true . And I track 2 more events: window.onkeyup and window.onblur . If window.onkeyup told me that the Ctrl key was released, then the variable __ctrl = false . And if the window.onblur event is triggered, then the variable is also __ctrl = false .

Question: Is it all right? In principle, everything works. Or you need to track some more events. Those. there will not be such a situation that in fact the Ctrl key is released, and the variable __ctrl = true ?

Example:

 var __ctrl = false; window.onkeydown = function( e ){ if( e.keyCode == 17 ){ __ctrl = true; } }; window.onkeyup = function( e ){ if( e.keyCode == 17 ){ __ctrl = false; } }; window.onblue = function(){ __ctrl = false; }; 

This __ctrl variable __ctrl needed so that for example the user wants to select several elements by holding the control and clicking the mouse.

  • In any case, the ctrlKey property is for an object of type KeyboardEvent in the MDN documentation , so you can count on it. - Regent
  • Here it is, it turns out. Why not just use the ctrlKey property ctrlKey ? - Regent
  • If not difficult, you can example? - wolter_white
  • In this question there is an example in the second answer. In general, after all, from the documentation it is clear what it is and how to use it. - Regent

0