$(window).keypress(function(event) {
if (event.which == 115 && event.ctrlKey){
myfunction();
}
});
myfunction(){
alert("Key pressed Ctrl+s");
}
When Ctrl+S was pressed, I don't see this myfunction is trigger. Can anyone help.? I am new to jQuery. Thanks in advance.
Listen for keyup
and keydown
. Also, the key code for 's' is 83. This reliably works:
$(document).bind("keyup keydown", function(e){
if(e.ctrlKey && e.which == 83){
myfunction();
}
});
function myfunction(){
alert("Key pressed Ctrl+s");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With