So, that's the question =)
How to capture mac's command key via javascript?
So, that's the question =)
How to capture mac's command key via javascript?
var element = //the DOM element to listen for the key on.
element.onkeyup = function(e) {
if(e.metaKey) {
//command key was pressed
}
}
Unlike Shift/Alt/Ctrl, Mac/Apple key is not considered as a modifier key--instead, you should hook on keydown/keyup and record when a key is pressed and then depressed based on event.keyCode.
Unfortunately, these key codes are browser-dependent:
Firefox: 224
Opera: 17
WebKit (Safari/Chrome): 91 (Left Apple) or 93 (Right Apple)
You might be interested in reading this article: JavaScript Madness: Keyboard Events from which I mastered that knowledge.