I am building a userscript with Tampermonkey that recognizes keycode events and when the key is fired it will do a function.
for eg. I want to press Enter and its keycode
is 13 so I used this code
$(document).keypress(function(event){
var which = (event.which ? event.which : event.keyCode);
if(which == '13'){
alert("You Pressed Enter key");
}
else if(which == '17'){
alert("You Pressed Control key");
}
});
The code works fine with Enter and with 1 but doesn't work with Ctrl nor Shift and other keys.
Is there any thing I am missing or not all key events can be handled?
NOTE : I have been using this link to get my keycodes and using them in my script.