HTML Question

How do I capture when a user presses CTRL + S?

I have a website wich can save sessions but I think buttons are ugly so I thought that shortcuts would be easier, and I would prefer the onkeydown HTML tag function. The shortcut I want to use is CTRL + S. For example

<input type="text" onkeydown="if(event.keyCode == CTRL+S) saveSession()">

Answer Source

I'm in love with the Mousetrap library: https://craig.is/killing/mice. It normalizes keybindings with great browser support.

For example:

Mousetrap.bind('ctrl+s', function(e) {
    alert('Save!');
});

Since ctrl isn't used for saving on a Mac, you can bind multiple key combinations to the save function, e.g.

Mousetrap.bind(['ctrl+s', 'command+s'], function(e) {
    alert('Save!');
});