“JavaScript Keyboard” Ответ

Как добавить сочетание клавиш JavaScript

document.addEventListener("keydown", (event) => {
	/*
		event.key returns the character being pressed
        event.preventDefault() prevents the default browser behavior for that shortcut, e.g. ctrl+r usually reloads the page, but event.preventDefault() will turn off that behavior. event.preventDefault() should only be used if you share a shortcut with the same trigger as the browser.
        event.ctrlKey / event.altKey / event.shiftKey / event.metaKey all return booleans. They will be true when they are being pressed, otherwise they will be false.
	*/
	if (event.ctrlKey && event.key.toLowerCase() === "d") {
    	//Do something
	} else if (event.ctrlKey && event.key.toLowerCase() === "p") {
    	//Do something else
	}
});	
Spen

JS ярлык

document.addEventListener('keydown', (e) => {
  if (e.ctrlKey && String.fromCharCode(e.keyCode).toLowerCase() === 's') {
    e.preventDefault();
    e.stopPropagation();
    // Do some stuff...
  }
}, false);
garzj

JavaScript Keyboard

document.onkeyup = function(e) {
    if (e.which == 16) {
        alert('You have press Shift')
    }
    if (e.which == 17 && e.which == 13) {
        alert('You have press CTRL + Enter')
    }
    //Keyboard events codes
    //https://www.toptal.com/developers/keycode
};
Marco Tellez

Ответы похожие на “JavaScript Keyboard”

Вопросы похожие на “JavaScript Keyboard”

Больше похожих ответов на “JavaScript Keyboard” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования