-2

I am writing a script where I need to know if a user has pressed ctrl+s or ctrl+p. How do I do this. Help would be appreciated. the problem is as soon as the user presses ctrl+s the page doesn't go to script, it directly gets saved.

JJJ
  • 32,902
  • 20
  • 89
  • 102
user2039532
  • 31
  • 1
  • 6
  • 3
    take a look at: http://stackoverflow.com/questions/93695/best-cross-browser-method-to-capture-ctrls-with-jquery – vikasing Feb 24 '13 at 07:02
  • I suggest to check [this](http://stackoverflow.com/questions/14860759/cant-override-ctrls-in-firefox-using-jquery-hotkeys) (btw, maybe your question is a duplicate). – lxgreen Feb 24 '13 at 07:18

2 Answers2

4

Updated:DEMO

$(document).keydown(function(e){
if (e.keyCode==80 && e.ctrlKey)
    $("body").append("<p>ctrl+p detected!</p>");
});
coder
  • 13,002
  • 31
  • 112
  • 214
0

You have to write a script that listens to and cancels the onkeydown event so the browser doesn't do the default behavior. Or maybe use a script like this? http://www.stepanreznikov.com/js-shortcuts/

Adam Brill
  • 330
  • 1
  • 5
  • well guys , it worked and here is the code. include www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js and save it in the same folder as you html code – user2039532 Feb 24 '13 at 07:52