You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/7-keyboard-events/article.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,51 +103,51 @@ Se andiamo a controllare `event.code == 'KeyZ'` nel nostro codice, per gli utent
103
103
104
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.
105
105
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).
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, questo avviene solo con alcuni codici, ad esempio `keyA`, `keyQ`, `keyZ` (come abbiamo visto), e non avviene con i tasti speciali come`Shift`. Si può vedere la lista nelle [specifiche](https://www.w3.org/TR/uievents-code/#table-key-code-alphanumeric-writing-system).
107
107
108
-
To reliably track layout-dependent characters, `event.key`may be a better way.
108
+
Per il tracciamento affidabile di carattere dipendenti dal layout, `event.key`potrebbe essere la soluzione migliore.
109
109
110
-
On the other hand, `event.code`has the benefit of staying always the same, bound to the physical key location, even if the visitor changes languages. So hotkeys that rely on it work well even in case of a language switch.
110
+
D'altra parte, `event.code`ha il beneficio di essere sempre lo stesso, legato alla posizione fisica del tasto, anche se il visitatore dovesse modificare la lingua. Quindi le scorciatoie relative ad essi funzionano bene anche in caso di cambio lingua.
111
111
112
-
Do we want to handle layout-dependant keys? Then`event.key`is the way to go.
112
+
Vogliamo gestire dei tasti dipendenti dal layout? Allora`event.key`è la quello che fa per noi.
113
113
114
-
Or we want a hotkey to work even after a language switch? Then`event.code`may be better.
114
+
Oppure volgiamo una scorciatoia che funzioni anche al cambio lingua? Allora`event.code`potrebbe essere meglio.
115
115
116
116
## Auto-repeat
117
117
118
-
If a key is being pressed for a long enough time, it starts to "auto-repeat": the`keydown`triggers again and again, and then when it's released we finally get `keyup`. So it's kind of normal to have many `keydown`and a single`keyup`.
118
+
Se un tasto viene premuto abbastanza a lungo, comincia l'"auto-repeat": l'evento`keydown`viene scaturito ancora e ancora, e alla fine quando verrà rilasciato otterremo un evento `keyup`. Quindi è abbastanza normale avere molti `keydown`e un solo`keyup`.
119
119
120
-
For events triggered by auto-repeat, the event object has `event.repeat`property set to`true`.
120
+
Per eventi generati da auto-repeat, l'oggetto evento ha la proprietà `event.repeat`impostata a`true`.
121
121
122
122
123
-
## Default actions
123
+
## Azioni default
124
124
125
-
Default actions vary, as there are many possible things that may be initiated by the keyboard.
125
+
Le azioni di default possono variare, dal momento che sono tante le cose che possono essere iniziate con la tastiera.
126
126
127
-
For instance:
127
+
Per esempio:
128
128
129
-
-A character appears on the screen (the most obvious outcome).
130
-
-A character is deleted (`key:Delete` key).
131
-
-The page is scrolled (`key:PageDown` key).
132
-
-The browser opens the "Save Page" dialog (`key:Ctrl+S`)
133
-
- ...and so on.
129
+
-Compare un carattere sullo schermo (lo scenario più ovvio).
130
+
-Viene cancellato un carattere (tasto `key:Delete`).
131
+
-Si scrolla la pagina (tasto `key:PageDown`).
132
+
-Il browser apre la finestra di dialogo "Sala la Pagina" (`key:Ctrl+S`)
133
+
- ...e così via.
134
134
135
-
Preventing the default action on `keydown`can cancel most of them, with the exception of OS-based special keys. For instance, on Windows `key:Alt+F4`closes the current browser window. And there's no way to stop it by preventing the default action in JavaScript.
135
+
Prevenire le azioni di default sul `keydown`può annullare la maggioranza di essere, con l'eccezione delle combinazioni di tasti del sistema operativo. Per esempio, su Windows `key:Alt+F4`chiude la finestra attuale del browser. E non c'è modo per prevenire questa azione predefinita tramite JavaScript.
136
136
137
-
For instance, the `<input>`below expects a phone number, so it does not accept keys except digits, `+`, `()` or `-`:
137
+
Per esempio, il seguene campo `<input>`si aspetta un numero di telefono, quindi nn accetta tasti che non siano numeri, `+`, `()` or `-`:
<input*!*onkeydown="return checkPhoneKey(event.key)"*/!*placeholder="Numero di telefono, per piacere"type="tel">
146
146
```
147
147
148
-
Please note that special keys, such as `key:Backspace`, `key:Left`, `key:Right`, `key:Ctrl+V`, do not work in the input. That's a side-effect of the strict filter`checkPhoneKey`.
148
+
È interessante notare che i tasti speciali, come `key:Backspace`, `key:Left`, `key:Right`, `key:Ctrl+V`, non funzionano nel campo input. Questo è un effetto collaterale delle restrizioni del filtro`checkPhoneKey`.
149
149
150
-
Let's relax it a little bit:
150
+
Facciamolo "rilassare" un attimo:
151
151
152
152
153
153
```html autorun height=60 run
@@ -160,19 +160,19 @@ function checkPhoneKey(key) {
...But we still can enter anything by using a mouse and right-click + Paste. So the filter is not 100% reliable. We can just let it be like that, because most of time it works. Or an alternative approach would be to track the`input` event -- it triggers after any modification. There we can check the new value and highlight/modify it when it's invalid.
165
+
...Ma possiamo ancora inserire qualunque valore usando il mouse e facendo tasto destro + Incolla. Quindi il filtro non è al 100% affidabile. Possiamo solo lasciarlo così, dato che funzionerà la maggior parte delle volte. O un approccio alternativo potrebbe essere quello di tenere traccia dell'evento`input`, che viene scaturito dopo ogni modifica. A quel punto, possiamo verificare il nuovo valore e evidenziarlo/modificarlo se non valido.
166
166
167
-
## Legacy
167
+
## Eredità
168
168
169
-
In the past, there was a`keypress` event, and also `keyCode`, `charCode`, `which`properties of the event object.
169
+
Nel passato, c'era un evento`keypress`, ed anche le proprietà `keyCode`, `charCode`, `which`dell'oggetto evento.
170
170
171
-
There were so many browser incompatibilities while working with them, that developers of the specification had no way, other than deprecating all of them and creating new, modern events (described above in this chapter). The old code still works, as browsers keep supporting them, but there's totally no need to use those any more.
171
+
C'erano tante di quelle incompatibilità tra i vari browser anche mentre ci stavano lavorando, che gli sviluppatori delle specifiche non avevano modo che deprecarli tutti e creare dei nuovi e moderni eventi (descritti sopra in questo capitolo). Il codice vecchio funziona ancora, da momento che i broweser continuano a supportarli, ma assolutamente non c'è nessuna ragione per continuare a farlo.
172
172
173
-
## Mobile Keyboards
173
+
## Tastiere dei dispositivi mobile
174
174
175
-
When using virtual/mobile keyboards, formally known as IME (Input-Method Editor), the W3C standard states that a KeyboardEvent's [`e.keyCode` should be `229`](https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode) and [`e.key` should be `"Unidentified"`](https://www.w3.org/TR/uievents-key/#key-attr-values).
175
+
Usando le tastiere virtuali dei dispositivi mobile, conosciute formalmente come IME (Input-Method Editor), the W3C standard states that a KeyboardEvent's [`e.keyCode` should be `229`](https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode) and [`e.key` should be `"Unidentified"`](https://www.w3.org/TR/uievents-key/#key-attr-values).
176
176
177
177
While some of these keyboards might still use the right values for `e.key`, `e.code`, `e.keyCode`... when pressing certain keys such as arrows or backspace, there's no guarantee, so your keyboard logic might not always work on mobile devices.
0 commit comments