2

I've been searching SO and the remaining internet, and I can't find a straight answer anywhere. How might someone execute javascript function aFunction when key m is pressed and released while no element (text box, etc) is focused?

1 Answer 1

4

With jQuery

$('body').keypress(function(e){
  if(e.which == 109)
    aFunction();
})

Here is a demo on jsFiddle

Edit: lowercase m is 109

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

4 Comments

Just try it yourself $("body").keypress(function(e){console.log(e.which)});
@30n This just isn't working... I have linked jquery, and I have a <script /> with the code you gave me, and I've tried many keys, while nothing else is selected. Is there something I'm missing?
Typing on azerty on a qwerty keyboard I got missed up sorry.
@lucase.62 I guess you can close the question.

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.