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
With jQuery
$('body').keypress(function(e){
if(e.which == 109)
aFunction();
})
Here is a demo on jsFiddle
Edit: lowercase m is 109
4 Comments
3on
Just try it yourself
$("body").keypress(function(e){console.log(e.which)});tkbx
@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?
3on
Typing on azerty on a qwerty keyboard I got missed up sorry.
3on
@lucase.62 I guess you can close the question.