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.
ctrlKeyproperty is for an object of typeKeyboardEventin the MDN documentation , so you can count on it. - RegentctrlKeypropertyctrlKey? - Regent