default Mac keyboard shortcut in safari, I want to overwrite them. such as cmd+s, cmd+n
let isMeta = false;
window.onkeydown = e => {
if(e.key == "Meta"){
isMeta = true;
}else if(e.key == 's' && isMeta){
e.preventDefault();
console.log('s');
}else if(e.key == 'n' && isMeta){
e.preventDefault();
console.log('n');
}
};
window.onkeyup = e => {
if(e.key == "Meta"){
isMeta = false;
}
};
testing result: cmd+s succeeded, when I press the shortcut, saving action is prevented and s is logged. but ctrl+n will call default opening new tab and n is not logged.
I wonder why this happens, why one works but the other.