Answers for "javascript check if command key is pressed"

1

how to see if user clicked key in js

document.addEventListener("keyup", function(event) {
    if (event.keyCode === 13) {
        alert('Enter is pressed!');
    }
});
Posted by: Guest on April-25-2021
14

js when key is pressed

document.addEventListener("keypress", function(event) {
	// do stuff
});
Posted by: Guest on March-08-2020
0

js detect cmd+s

// To detect Cmd key pressed, check Event.key === 'Meta'
document.querySelectorAll('#form').forEach(form => {
	let meta_pressed = false;
	form.addEventListener('keydown', e => {
		if ( e.key === 'Meta' ) {
			meta_pressed = true;
		} else if ( e.key === 's' ) {
          	// Keep the browser from running its own
          	// Cmd+S (Save Page As...) function
			e.preventDefault();
			form.submit();
		}
	});
	form.addEventListener('keyup', e => {
		if ( e.key === 'Meta' ) {
			meta_pressed = false;
		}
	});
});
Posted by: Guest on July-07-2020

Code answers related to "javascript check if command key is pressed"

Code answers related to "Javascript"

Browse Popular Code Answers by Language