capricorn86/happy-dom

KeyboardEvent is missing getModifierState

Opened this issue · 1 comments

Describe the bug
getModifierState is undefined on KeyboardEvent.

To Reproduce

const event = new KeyboardEvent('keydown', { key: ']' });
console.info(event.getModifierState('Shift') === false);

this should return true instead i get TypeError: event.getModifierState is not a function

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState

maybe something like this?

KeyboardEvent.prototype.getModifierState = function (key: string) {
  const modifierKeys = {
    Alt: this.altKey,
    Control: this.ctrlKey,
    Meta: this.metaKey,
    Shift: this.shiftKey,
  };

  return !!modifierKeys[key];
};