最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - KeyCode for Windows Key? - Stack Overflow

programmeradmin14浏览0评论

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.

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.

Share Improve this question asked Apr 6, 2016 at 17:48 ArloArlo 9903 gold badges11 silver badges21 bronze badges 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. – Diego Polido Santana 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 – Diego Polido Santana 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. – zzzzBov Commented Apr 6, 2016 at 18:06
Add a comment  | 

2 Answers 2

Reset to default 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

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

document.onkeydown = function(evt){ 
    console.log(evt.keyCode);
}
发布评论

评论列表(0)

  1. 暂无评论