0

I am trying to press "windows" + ";" key using javaScript/Jquery.Is there any way to do that?

am232
  • 1
  • 4

1 Answers1

0

You can create a new KeyboardEvent with metaKey and keyCode properties set as following:

document.addEventListener('keypress', (event) => {
  console.log('Meta Key?', event.metaKey);
  console.log('Key Code', event.which);
});

document.dispatchEvent(new KeyboardEvent('keypress', {
  metaKey: true, // On Windows, this is "window" key
  keyCode: 44 // This is keyCode of comma on Windows-US
}))

BUT, I'm not sure about browser support of this behavior.

Here's the list of keyCodes: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

Hope this helps.

Harun Yilmaz
  • 8,281
  • 3
  • 24
  • 35