$(document).bind('keyup', function(e){ if(e.which==78) {
To prevent input focusing:
$("body").on("focus",":input", function(){ $(document).unbind('keyup'); }); $("body").on("blur",":input", function(){ $(document).bind('keyup', function(e){ etc.... });
You might want to include the bind
function in your own function so as not to duplicate the code. eg:
function bindKeyup(){ $(document).bind('keyup', function(e){ if(e.which==78) { // "n" } if(e.which==83) { // "s" } }); } $("body").on("focus",":input", function(){ $(document).unbind('keyup'); }); $("body").on("blur",":input", function(){ bindKeyup(); });
source share