In jQuery, we can use 'window.onkeydown' to trigger action when a key is pressed. But 'onkeydown' will 'continuously' execute the function that we have assigned for the trigger. Is there a way that we can execute the assigned function only one time? Thank you!
On key down is specially annoying when I do something like:
window.onkeydown = function(e){
if (e.keyCode == 17){
jQuery('<h2/>').appendTo($('#myDiv'))
}
}
In this case, as long as I hold down the Ctrl key (keyCode 17), jQuery will continuously create h2 elements inside the #myDiv, and the result I want is just 1 h2 is created.