How can I know macOS command keys in JavaScript.
Need to know left and right command keys. I know key codes of these both but I don't know how to separate from other keys.
How can I know macOS command keys in JavaScript.
Need to know left and right command keys. I know key codes of these both but I don't know how to separate from other keys.
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.org/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.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>