Skip to content

Commit c364920

Browse files
prima parte tradotta
1 parent a1d8278 commit c364920

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

2-ui/3-event-details/7-keyboard-events/article.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
# Keyboard: keydown and keyup
1+
# Tastiera: keydown e keyup
22

3-
Before we get to keyboard, please note that on modern devices there are other ways to "input something". For instance, people use speech recognition (especially on mobile devices) or copy/paste with the mouse.
3+
Prima di andare alla tastiera, è bene ricordare che nei dispositivi moderni esistono altre maniere per "inserire qualche dato". Per esempio citiamo l'uso del riconoscimento vocale (specialmente sui dispositivi mobile) o il copia/incolla con il mouse.
44

5-
So if we want to track any input into an `<input>` field, then keyboard events are not enough. There's another event named `input` to track changes of an `<input>` field, by any means. And it may be a better choice for such task. We'll cover it later in the chapter <info:events-change-input>.
5+
Quindi se vogliamo tenere traccia di qualunque input dentro un campo `<input>`, allora gli eventi della tastiera non saranno sufficienti. Esite però un altro evento chiamato `input` per tenere traccia delle modifiche su un `<input>`, di qualunque natura. E questa potrebbe essere la scelta corretta per qursto tipo di attività. Verrà affrontato più avanti nel capitolo <info:events-change-input>.
66

7-
Keyboard events should be used when we want to handle keyboard actions (virtual keyboard also counts). For instance, to react on arrow keys `key:Up` and `key:Down` or hotkeys (including combinations of keys).
7+
Gli eventi della tastiera dovrebbero essere usati per gestire azioni da tastiera (comprese le tastiere virtuali). Per esempio, per reagire ai tasti freccia `key:Up` e `key:Down` oppure alle scorciatoie (includendo quindi combinazioni di tasti).
88

99

10-
## Teststand [#keyboard-test-stand]
10+
## Banco di test [#keyboard-test-stand]
1111

1212
```offline
13-
To better understand keyboard events, you can use the [teststand](sandbox:keyboard-dump).
13+
Per capire meglio gli eventi da tastiera, possiamo usare il [banco di test](sandbox:keyboard-dump).
1414
```
1515

1616
```online
17-
To better understand keyboard events, you can use the teststand below.
17+
Per capire meglio gli eventi da tastiera, possiamo usare il seguente banco di test.
1818
19-
Try different key combinations in the text field.
19+
Proviamo diverse combinazioni di tasti nel campo di testo.
2020
2121
[codetabs src="keyboard-dump" height=480]
2222
```
2323

2424

25-
## Keydown and keyup
25+
## Keydown e keyup
2626

27-
The `keydown` events happens when a key is pressed down, and then `keyup` -- when it's released.
27+
L'evento `keydown` avviene quando viene premuto un tasto, e `keyup` quando viene rilasciato.
2828

29-
### event.code and event.key
29+
### event.code e event.key
3030

31-
The `key` property of the event object allows to get the character, while the `code` property of the event object allows to get the "physical key code".
31+
La proprietà `key` dell'oggetto evento, permette di ottenere il carattere, mentre la proprietà `code` ci restituisce "codice del tasto fisico".
3232

33-
For instance, the same key `key:Z` can be pressed with or without `key:Shift`. That gives us two different characters: lowercase `z` and uppercase `Z`.
33+
Ad esempio, a parità di `key:Z` potrebbe essere stato premuto con o senza il `key:Shift`. Questo potrebbe darci due differenti caratteri: minuscolo `z` e maiuscolo `Z`.
3434

35-
The `event.key` is exactly the character, and it will be different. But `event.code` is the same:
35+
`event.key` è esattamente il carattere, e sarà differente. Invece `event.code` è sempre lo stesso:
3636

3737
| Key | `event.key` | `event.code` |
3838
|--------------|-------------|--------------|
39-
| `key:Z` |`z` (lowercase) |`KeyZ` |
40-
| `key:Shift+Z`|`Z` (uppercase) |`KeyZ` |
39+
| `key:Z` |`z` (minuscolo) |`KeyZ` |
40+
| `key:Shift+Z`|`Z` (maiuscolo) |`KeyZ` |
4141

4242

43-
If a user works with different languages, then switching to another language would make a totally different character instead of `"Z"`. That will become the value of `event.key`, while `event.code` is always the same: `"KeyZ"`.
43+
Se un utente fa uso di diverse lingue, passare ad un'altra significherebbe avere tutt'altro carattere rispetto a `"Z"`. Quest'ultimo diverrebbe il valore di `event.key`, mentre `event.code` sarebbe sempre `"KeyZ"`.
4444

45-
```smart header="\"KeyZ\" and other key codes"
46-
Every key has the code that depends on its location on the keyboard. Key codes described in the [UI Events code specification](https://www.w3.org/TR/uievents-code/).
45+
```smart header="\"KeyZ\" e altri codici tasto"
46+
Ogni tasto ha un codice che dipende dalla sua posizione sulla tastiera. I codici dei tasti vengono descritti nelle [specifiche dei codici Evento UI](https://www.w3.org/TR/uievents-code/).
4747
48-
For instance:
49-
- Letter keys have codes `"Key<letter>"`: `"KeyA"`, `"KeyB"` etc.
50-
- Digit keys have codes: `"Digit<number>"`: `"Digit0"`, `"Digit1"` etc.
51-
- Special keys are coded by their names: `"Enter"`, `"Backspace"`, `"Tab"` etc.
48+
Per esempio:
49+
- I tasti lettera hanno dei codici: `"Key<letter>"`: `"KeyA"`, `"KeyB"` etc.
50+
- I tasti numerici hanno dei codici: `"Digit<number>"`: `"Digit0"`, `"Digit1"` etc.
51+
- I tasti speciali sono codificati con i loro nomi: `"Enter"`, `"Backspace"`, `"Tab"` etc.
5252
53-
There are several widespread keyboard layouts, and the specification gives key codes for each of them.
53+
Esiste una grande varietà di layout di tastiera, e le specifiche danno un codice per ognuno di essi.
5454
55-
Read the [alphanumeric section of the spec](https://www.w3.org/TR/uievents-code/#key-alphanumeric-section) for more codes, or just press a key in the [teststand](#keyboard-test-stand) above.
55+
Per avere informazioni sui vari codici [sezione alfanumerica delle specifiche](https://www.w3.org/TR/uievents-code/#key-alphanumeric-section), oppure basta premere un tasto nel [banco di test](#keyboard-test-stand) precedente.
5656
```
5757

58-
```warn header="Case matters: `\"KeyZ\"`, not `\"keyZ\"`"
59-
Seems obvious, but people still make mistakes.
58+
```warn header="La distinzione tra maiuscolo e minuscolo è importante: `\"KeyZ\"`, e non `\"keyZ\"`"
59+
Sembra ovvio, ma le persone sbagliano ancora.
6060

61-
Please evade mistypes: it's `KeyZ`, not `keyZ`. The check like `event.code=="keyZ"` won't work: the first letter of `"Key"` must be uppercase.
61+
Bisogna evitare di scrivere in modo scorretto: è `KeyZ`, e non `keyZ`. Un controllo fatto in questo modo `event.code=="keyZ"` non funziona: la prima lettera di `"Key"` deve essere maiuscaola.
6262
```
6363
64-
What if a key does not give any character? For instance, `key:Shift` or `key:F1` or others. For those keys, `event.key` is approximately the same as `event.code`:
64+
Cosa succederebbe se un tasto non restituisse nessun carattere? Per esempio, `key:Shift` oppure `key:F1` o altri ancora. Per questi tasti il valore di `event.key` è approssiamtivamente lo stesso di `event.code`:
6565
6666
| Key | `event.key` | `event.code` |
6767
|--------------|-------------|--------------|
6868
| `key:F1` |`F1` |`F1` |
6969
| `key:Backspace` |`Backspace` |`Backspace` |
7070
| `key:Shift`|`Shift` |`ShiftRight` or `ShiftLeft` |
7171
72-
Please note that `event.code` specifies exactly which key is pressed. For instance, most keyboards have two `key:Shift` keys: on the left and on the right side. The `event.code` tells us exactly which one was pressed, and `event.key` is responsible for the "meaning" of the key: what it is (a "Shift").
72+
Nota bene che `event.code` specifica esattamente il tasto premuto. Per esempio, la maggioranza delle tastiere hanno due tasti `key:Shift`: uno nel lato sinistro e uno nel lato destro. `event.code` ci dice esattamente quale viene premuto, ed `event.key` è responsable invece del "significato" del tasto: cosa è (uno "Shift").
7373
74-
Let's say, we want to handle a hotkey: `key:Ctrl+Z` (or `key:Cmd+Z` for Mac). Most text editors hook the "Undo" action on it. We can set a listener on `keydown` and check which key is pressed.
74+
Mettiamo il caso che volessimo gestire una scorciatoia: `key:Ctrl+Z` (o `key:Cmd+Z` su Mac). La maggiorparte degli editor di testo aggancia su di esso l'azione "Undo". Possiamo impostare un listener sul `keydown` e controllare quale tasto viene premuto.
7575
76-
There's a dilemma here: in such a listener, should we check the value of `event.key` or `event.code`?
76+
Ma qui c'è un dilemma: in questo listener, dovremmo controllare il valore di `event.key` oppure quello di `event.code`?
7777
78-
On one hand, the value of `event.key` is a character, it changes depending on the language. If the visitor has several languages in OS and switches between them, the same key gives different characters. So it makes sense to check `event.code`, it's always the same.
78+
Da una parte, il valore di `event.key` è un carattere, e cambia a seconda del linguaggio. Se il visitatore ha più lingue nel suo sistema operativo e passa da uno all'altro, lo stesso tasto restituirà caratteri differenti. Quindi ha senso controllare `event.code`, che è sempre lo stesso.
7979
80-
Like this:
80+
Ecco un esempio:
8181
8282
```js run
8383
document.addEventListener('keydown', function(event) {
@@ -87,23 +87,23 @@ document.addEventListener('keydown', function(event) {
8787
});
8888
```
8989

90-
On the other hand, there's a problem with `event.code`. For different keyboard layouts, the same key may have different characters.
90+
D'altra parte, c'è un problema con `event.code`. Per layout di tastiera differenti, possono corrispondere caratteri differenti.
9191

92-
For example, here are US layout ("QWERTY") and German layout ("QWERTZ") under it (from Wikipedia):
92+
Per esempio, qui abbiamo un layout americano ("QWERTY") ed un layout Tedesco ("QWERTZ") sotto di esso (da Wikipedia):
9393

9494
![](us-layout.svg)
9595

9696
![](german-layout.svg)
9797

98-
For the same key, US layout has "Z", while German layout has "Y" (letters are swapped).
98+
A parità di tasto, sul layout americano corrisponde a "Z", mentre per quello tedesco corrisponde a "Y" (le lettere sono scambiate tra di loro).
9999

100-
Literally, `event.code` will equal `KeyZ` for people with German layout when they press `key:Y`.
100+
Letteralmente, `event.code` equivale a `KeyZ` per gli utenti con il layout tedesco quando premono `key:Y`.
101101

102-
If we check `event.code == 'KeyZ'` in our code, then for people with German layout such test will pass when they press `key:Y`.
102+
Se andiamo a controllare `event.code == 'KeyZ'` nel nostro codice, per gli utenti con il layout tedesco, il test passerà alla pressione del tasto `key:Y`.
103103

104-
That sounds really odd, but so it is. The [specification](https://www.w3.org/TR/uievents-code/#table-key-code-alphanumeric-writing-system) explicitly mentions such behavior.
104+
Questo può sembrare strano,ma è così. Le [specifiche](https://www.w3.org/TR/uievents-code/#table-key-code-alphanumeric-writing-system) menzionano in modo esplicito questo comportamento.
105105

106-
So, `event.code` may match a wrong character for unexpected layout. Same letters in different layouts may map to different physical keys, leading to different codes. Luckily, that happens only with several codes, e.g. `keyA`, `keyQ`, `keyZ` (as we've seen), and doesn't happen with special keys such as `Shift`. You can find the list in the [specification](https://www.w3.org/TR/uievents-code/#table-key-code-alphanumeric-writing-system).
106+
Quindi, `event.code` può corrispondere a un carattere errato da layout inaspettati. A parità di lettera, per layout differenti potrebbero essere mappati a tasti fisici differenti, portando a codici differenti. Fortunatamente, that happens only with several codes, e.g. `keyA`, `keyQ`, `keyZ` (as we've seen), and doesn't happen with special keys such as `Shift`. You can find the list in the [specification](https://www.w3.org/TR/uievents-code/#table-key-code-alphanumeric-writing-system).
107107

108108
To reliably track layout-dependent characters, `event.key` may be a better way.
109109

0 commit comments

Comments
 (0)