4

Is there a keyCode for the Windows key or a way to detect when it is pressed with Javascript or jQuery?

I've dug through StackOverflow and have found how to detect command for Mac and Ctrl and Alt for Mac and Windows, but can't find any solutions for detecting when the user presses Windows Key. Not sure if it's just a metaKey like command is but represented by the Windows Flag, or if it's even detectable at all.

3
  • 1
    So, this button triggers a windows menu and leaves focus from the browser.. I'm not sure if it's possible. But why do you need this? maybe you can handle otherwise. Commented Apr 6, 2016 at 17:52
  • You can try 91 or 92 (right and left button) but I'm not sure it will work Commented Apr 6, 2016 at 17:54
  • On a related note: if you happen to use jQuery UI be aware that it provides a (limited) convenience map of key names to keycodes at $.ui.keyCode. For example you can check $.ui.keyCode.DOWN instead of 40. Commented Apr 6, 2016 at 18:06

2 Answers 2

8

VK_LWIN 0x5B - Left Windows key (Natural keyboard) EDIT: This explains Ed's answer as hex 5B is 91

VK_RWIN 0x5C - Right Windows key (Natural keyboard)

SOURCE: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx

Also, per wikipedia:

The Windows key can also be used on other operating systems.

On Unix and Unix-like operating systems, it is sometimes called "Meta" or "Super".

SOURCE: https://en.wikipedia.org/wiki/Windows_key#Use_with_non-Microsoft_operating_systems

Sign up to request clarification or add additional context in comments.

Comments

7

I ran the following js and got 91 when pressing windows key.

document.onkeydown = function(evt){ console.log(evt.keyCode); } 

2 Comments

Just FYI I ran it on a Mac and the Command/Super key returns 224
I guess 91 is correct code for the "Windows" key, on non-Mac keyboards. The Mac "meta" key is an entirely different key.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.