You can have a global variable and set it to something when the text field is focused and reset it is blurred. Something like that:
var textboxSelected = false; $(":input").focus(function () { textboxSelected = true; }); $(":input").blur(function () { textboxSelected = false; });
Then, in your onKeyDown event, check if the variable is set to false before executing the remaining functionality:
$(window).keydown(function (evt) { if (evt.which == 46 && textboxSelected == false) { goDoSomething(); } });
user1636130
source share