Monday, May 20, 2024
164
rated 0 times [  167] [ 3]  / answers: 1 / hits: 15151  / 9 Years ago, wed, august 5, 2015, 12:00:00

So I want to test if visitors of my site have pressed Print Screen button.



As much as I was looking for, there were no information to be found how to do it. All I found was, that ir is supposed to be keyCode == 44.



With all the other buttons I tried there was no problem.



Where is my mistake?



Here's similar, working code for enter button:



window.addEventListener(keydown, checkKeyPressed, false);

function checkKeyPressed(e) {
if (e.keyCode == 13) {
alert(The 'enter' key is pressed.);
}
}

More From » event-listener

 Answers
10
window.addEventListener(keyup, function(e) {
if (e.keyCode == 44) {
alert(The 'print screen' key is pressed);
}
});


Note keyup and not keydown.



Honestly, I have no idea why this works and not the other, but I think it may have something to do with the OS intercepting it on press and (somehow?) blocking the event.


[#65532] Monday, August 3, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;