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.
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?