command + C in my application I want to open the menu button. By default command key executed behalf of command + c. How to override the command key
Asked
Active
Viewed 66 times
1 Answers
1
You can prevent the default key combination action to be executed using the preventDefault function:
function KeyPress(e) {
e.preventDefault();
var evtobj = window.event ? event : e;
if (evtobj.keyCode == 80 && evtobj.ctrlKey) {
console.log("Key combination: Ctrl + p");
}
}
document.onkeydown = KeyPress;
The document.onkeydown
sentence is adding the event function to all the document, so it will be triggered when any element in the website is selected/focused.
Unfortunately, like is answered in this post How does one capture a Mac's command key via JavaScript?, there is not an standard key code for the iOS command key, and it is browser dependant:
- Firefox: 224
- Opera: 17
- WebKit browsers (Safari/Chrome): 91 (Left Command) or 93 (Right Command)
You can check the key codes here: https://keycode.info/

fguini
- 326
- 1
- 5