Detect browser keyboard presses, with control

If you want to detect when control is pressed, or similar, then:

window.addEventListener("keydown", event => {
    if (!(event.which == 115 && event.ctrlKey)) return true;
    alert("Ctrl-S pressed");
    // don't do what it normally does
    event.preventDefault();
    // don't continune propagating the event
    return false;
})
javascript

Edit on github
comments powered by Disqus
Click me