I have overriden onkeyup and onkeydown functions in my web application and i would like to use the keyboard's pause/break key.
But it seems that this is a special key and has a strange behaviour. After a keydown event it fires a keyup immediately, even if you use preventDefault() and stopPropagation() methods.
The following script should demonstrate the behaviour clearly. First press and hold space bar. No alert should pop up until you take your hand off the space key. Then try the same with pause/break key and you should get the alert as soon as you press down the key.
https://jsfiddle.net/at3L9o73/2/
window.onkeydown = keydown;
window.onkeyup = keyup;
function keydown(event)
{
if(event.keyCode == 19)
{
event.preventDefault();
event.stopPropagation();
console.log("break down");
}
else if(event.keyCode == 32)
{
event.preventDefault();
event.stopPropagation();
console.log("space down");
}
}
function keyup(event)
{
if(event.keyCode == 19)
{
event.preventDefault();
event.stopPropagation();
console.log("break up");
window.alert("break keyp????");
}
else if(event.keyCode == 32)
{
event.preventDefault();
event.stopPropagation();
console.log("space up");
window.alert("space keyp");
}
}
Thanks in advance