“Pintasan keyboard JavaScript” Kode Jawaban

Cara Menambahkan JavaScript Pintasan Keyboard

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 Pintasan

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

Pintasan keyboard JavaScript

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

Jawaban yang mirip dengan “Pintasan keyboard JavaScript”

Pertanyaan yang mirip dengan “Pintasan keyboard JavaScript”

Lebih banyak jawaban terkait untuk “Pintasan keyboard JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya