IE doesn't detect Prt Scn key's keyup event (keyCode: 44) before other keyup event fire

121 views Asked by At

Here's my code

$(document).on("keyup", function(e) {
    console.log(e.key);
    if (e.key == "PrintScreen") {
        e.preventDefault();
        clearClipBoard();
    }
})

function clearClipBoard() {
    if (navigator.clipboard) { // Chrome or Edge
        navigator.clipboard.writeText(""); 
    }
    else if (window.clipboardData) { // Internet Explorer
        window.clipboardData.setData("Text", "");
    }
}

When the page loaded first time, or blur and focus back again, the keyup event of PrintScreen cannot be detected. But if I press other key first and then press the Prt Scn key, it can be detected successfully.

It only happens when using IE, when I using Chrome or Edge, it doesn't have this problem.

I've tried to trigger a keyup event of other key when the page focus back, but the Prt Scn key still cannot be detected.

$(window).on("focus", function() {
    $.alert("focus");
    let e = $.Event('keyup');
    e.key = 'a'; 
    $("body").trigger(e);
})

I found someome has the same question but no answer. IE 11 Print screen issue

Any one have any ideas what might be causing this issue?

0

There are 0 answers