Keyboard: keydown and keyup by pierangelomiceli · Pull Request #265 · javascript-tutorial/it.javascript.info
Expand Up
@@ -2,7 +2,7 @@
<html>
<body>
<p>Press "Q" and "W" together (can be in any language).</p> <p>Premere "Q" e "W" contemporaneamente (può essere in qualunque lingua).</p>
<script> function runOnKeys(func, ...codes) { Expand All @@ -11,19 +11,19 @@ document.addEventListener('keydown', function(event) { pressed.add(event.code);
for (let code of codes) { // are all keys in the set? for (let code of codes) { // le chiavi sono tutte contenute nel Set? if (!pressed.has(code)) { return; } }
// yes, they are // sì, lo sono
// during the alert, if the visitor releases the keys, // JavaScript does not get the "keyup" event // and pressed set will keep assuming that the key is pressed // so, to evade "sticky" keys, we reset the status // if the user wants to run the hotkey again - let them press all keys again // durante l'alert, se il visitatore rilascia i tasti, // JavaScript non cattura l'evento "keyup" // ed il set premuto verrà mantenuto, credendo che i tasti siano ancora premuti // quindi, per evitare tasti "incollati", resettiamo lo status // se l'utente vuole eseguire di nuovo la scorciatoia, premerà nuovamente pressed.clear();
func(); Expand Down
<p>Press "Q" and "W" together (can be in any language).</p> <p>Premere "Q" e "W" contemporaneamente (può essere in qualunque lingua).</p>
<script> function runOnKeys(func, ...codes) { Expand All @@ -11,19 +11,19 @@ document.addEventListener('keydown', function(event) { pressed.add(event.code);
for (let code of codes) { // are all keys in the set? for (let code of codes) { // le chiavi sono tutte contenute nel Set? if (!pressed.has(code)) { return; } }
// yes, they are // sì, lo sono
// during the alert, if the visitor releases the keys, // JavaScript does not get the "keyup" event // and pressed set will keep assuming that the key is pressed // so, to evade "sticky" keys, we reset the status // if the user wants to run the hotkey again - let them press all keys again // durante l'alert, se il visitatore rilascia i tasti, // JavaScript non cattura l'evento "keyup" // ed il set premuto verrà mantenuto, credendo che i tasti siano ancora premuti // quindi, per evitare tasti "incollati", resettiamo lo status // se l'utente vuole eseguire di nuovo la scorciatoia, premerà nuovamente pressed.clear();
func(); Expand Down