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

jquery - How can I detect macOS command keys in JavaScript - Stack Overflow

programmeradmin3浏览0评论

How can I know macOS mand keys in JavaScript.

Need to know left and right mand keys. I know key codes of these both but I don't know how to separate from other keys.

How can I know macOS mand keys in JavaScript.

Need to know left and right mand keys. I know key codes of these both but I don't know how to separate from other keys.

Share Improve this question edited Jan 31, 2017 at 6:12 tadman 212k23 gold badges236 silver badges265 bronze badges asked Jan 31, 2017 at 5:03 Shanmugaraja_KShanmugaraja_K 2,4323 gold badges15 silver badges26 bronze badges 3
  • Possible duplicate of jQuery key code for mand key – Alexander Elgin Commented Jan 31, 2017 at 5:54
  • See stackoverflow./a/3834210/92701 – Alexander Elgin Commented Jan 31, 2017 at 5:55
  • MAC refers to something very specific to do with networking. "Macintosh" or "Mac" is a trademark of Apple. – tadman Commented Jan 31, 2017 at 6:13
Add a ment  | 

2 Answers 2

Reset to default 5

You could look on keydown/keyup and record when a key is pressed based on event.keyCode.

Or as Alexander pointed out, you can also use:

event.metaKey https://developer.mozilla/en-US/docs/Web/API/MouseEvent/metaKey

There are some libraries which can help you out as these keys are browser dependent

See the snippet below

$(window).keydown(function (e){
    if (e.metaKey) {
      alert('meta key is pressed');
    }
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

发布评论

评论列表(0)

  1. 暂无评论