Jump to content

bind/unbind


Shadowing

Recommended Posts

Hey guys im trying to set up hot keys and I dont want them to affect when someone types in a input or text area The only way i can figure out how to do this is to have it where it disables the hot keys when a textarea/input is focus and then enable back again on blur but I cant figure out how to do this with bind and unbind

var hotkey = function() {    $(document).keydown(function(e){	               if (e.keyCode == 77) {                console.log("test");                		                  return false;	               }               });       }    $('input').bind('focus', hotkey);    $('input').unbind('blur', hotkey); 

Link to comment
Share on other sites

ahh i got it figured out

 var hotkey = function(e) {                   if (e.keyCode == 77) {                console.log("test");                		                  return false;	               }}  $(document).keydown(hotkey);$('input, textarea').focus(function(){ $(document).unbind('keydown', hotkey); });$('input, textarea').blur(function(){ $(document).bind('keydown', hotkey); });              });  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...