I am trying to debug a function using Firebug, for the JavaScript getModifierState() method seems to be not working. Here is the beginning of the function:
function kbdEq () {
$(document).on ('keypress', function (e) {
e.preventDefault();
debugger;
var x = e.charCode || e.keyCode;
// etc.
Jumping into Firebug is straightforward, but trying to test
e.getModifierState('Alt')
(or any other keyboard event as a parameter, with or without quotes) results in this message from Firebug:
e.getModifierState is not a function
I am using Firefox 44.0.2.
What mistake am I (presumably) making here?
As you are using jQuery, note that the event parameter (e in your case) is a jQuery specific object wrapping the actual event object.
To access the original event it has a property originalEvent. So, to access the modifier state you have to write this:
e.originalEvent.getModifierState("Alt");
Note that the jQuery event object has some simpler way to check whether the Alt, Ctrl, Shift or Meta key is pressed. This can be done via e.altKey, e.ctrlKey, e.shiftKey and e.metaKey, respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With