Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getModifierState() returned as an error

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?

like image 384
Brice Coustillas Avatar asked Feb 20 '16 10:02

Brice Coustillas


1 Answers

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.

like image 173
Sebastian Zartner Avatar answered Nov 03 '22 10:11

Sebastian Zartner