Skip to content

Commit 1d15273

Browse files
authored
Merge pull request #562 from joaquinelio/keso
2-3-7 task
2 parents a6c467e + 2d8bc81 commit 1d15273

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
We should use two handlers: `document.onkeydown` and `document.onkeyup`.
2+
Debemos manejar dos eventos: `document.onkeydown` y `document.onkeyup`.
33

4-
Let's create a set `pressed = new Set()` to keep currently pressed keys.
4+
Creemos un set `pressed = new Set()` para registrar las teclas presionads actualmente.
55

6-
The first handler adds to it, while the second one removes from it. Every time on `keydown` we check if we have enough keys pressed, and run the function if it is so.
6+
El primer manejador las agrega en él, mientras que el segundo las quita. Con cada `keydown` verificamos si tenemos suficientes teclas presionadas, y ejecutamos la función si es así.

2-ui/3-event-details/7-keyboard-events/2-check-sync-keydown/solution.view/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<body>
44

5-
<p>Press "Q" and "W" together (can be in any language).</p>
5+
<p>Presione "Q" y "W" juntas (puede ser en cualquier lenguaje).</p>
66

77
<script>
88
function runOnKeys(func, ...codes) {
@@ -11,19 +11,19 @@
1111
document.addEventListener('keydown', function(event) {
1212
pressed.add(event.code);
1313

14-
for (let code of codes) { // are all keys in the set?
14+
for (let code of codes) { // ¿están todas las teclas en el set?
1515
if (!pressed.has(code)) {
1616
return;
1717
}
1818
}
1919

20-
// yes, they are
20+
// sí, lo están
2121

22-
// during the alert, if the visitor releases the keys,
23-
// JavaScript does not get the "keyup" event
24-
// and pressed set will keep assuming that the key is pressed
25-
// so, to evade "sticky" keys, we reset the status
26-
// if the user wants to run the hotkey again - let them press all keys again
22+
// durante el alert, si el visitante suelta las teclas,
23+
// JavaScript no obtiene el evento "keyup"
24+
// y el set "pressed" las mantendrá asumiendo que las teclas siguen presionadas;
25+
// por ello, para evitar teclas "pegadas", reseteamos el estado
26+
// si el usuario quiere usa el atajo de nuevo, permitámoslo
2727
pressed.clear();
2828

2929
func();

2-ui/3-event-details/7-keyboard-events/2-check-sync-keydown/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ importance: 5
22

33
---
44

5-
# Extended hotkeys
5+
# Extendiendo atajos de teclado
66

7-
Create a function `runOnKeys(func, code1, code2, ... code_n)` that runs `func` on simultaneous pressing of keys with codes `code1`, `code2`, ..., `code_n`.
7+
Crea una función `runOnKeys(func, code1, code2, ... code_n)` que ejecute `func` al presionar simultáneamente las teclas con códigos `code1`, `code2`, ..., `code_n`.
88

9-
For instance, the code below shows `alert` when `"Q"` and `"W"` are pressed together (in any language, with or without CapsLock)
9+
Por ejemplo, el siguiente código muestra un `alert` cuando `"Q"` y `"W"` se presionan juntas (en cualquier lenguaje, con o sin mayúscula)
1010

1111
```js no-beautify
1212
runOnKeys(
13-
() => alert("Hello!"),
13+
() => alert("¡Hola!"),
1414
"KeyQ",
1515
"KeyW"
1616
);

2-ui/3-event-details/7-keyboard-events/keyboard-dump.view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<form id="form" onsubmit="return false">
1212

13-
Prevent default for:
13+
Evitar el predeterminado (prevent default) para:
1414
<label>
1515
<input type="checkbox" name="keydownStop" value="1"> keydown</label>&nbsp;&nbsp;&nbsp;
1616
<label>
@@ -24,7 +24,7 @@
2424
<input type="checkbox" name="keyupIgnore" value="1"> keyup</label>
2525
</p>
2626

27-
<p>Focus on the input field and press a key.</p>
27+
<p>Haz foco en el campo input y presiona una tecla.</p>
2828

2929
<input type="text" placeholder="Press keys here" id="kinput">
3030

0 commit comments

Comments
 (0)