1// To detect Cmd key pressed, check Event.key === 'Meta'
2document.querySelectorAll('#form').forEach(form => {
3 let meta_pressed = false;
4 form.addEventListener('keydown', e => {
5 if ( e.key === 'Meta' ) {
6 meta_pressed = true;
7 } else if ( e.key === 's' ) {
8 // Keep the browser from running its own
9 // Cmd+S (Save Page As...) function
10 e.preventDefault();
11 form.submit();
12 }
13 });
14 form.addEventListener('keyup', e => {
15 if ( e.key === 'Meta' ) {
16 meta_pressed = false;
17 }
18 });
19});