1

I am using js-hotkeys and when I press a hotkey like "f", it adds an f to the input field that I pulled up and focus on.

Is there anyway for it not to do that?

I also tried this other plugin http://rikrikrik.com/jquery/shortkeys/#download and it doesnt have that issue but then that plugin had other issue.

Thanks

1 Answer 1

4

You can prevent the default action using event.preventDefault(), in this case that default action is adding the letter to the textbox, for example:

$(document).bind('keydown', 'f', function(e) {
  $("input").focus();
  e.preventDefault();
});

Note: For those of you going WTF?: This is the syntax the plugin adds, it's not the normal .bind() jQuery core syntax.

I suggest you take a look at John Resig's re-write of the jQuery hotkeys plugin here, it's a much more efficient and 1.4.2+ compatible plugin, you can find the readme here.

See it in action here.

Sign up to request clarification or add additional context in comments.

1 Comment

ah brilliant yet again Nick. Actually I am using John's rewrite and it had the problem. But your suggestion fixed it. Seems like a bug on the plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.