* `charCode` represents the actual "character code" and is safe to use with * `String.fromCharCode`. As such, only keys that correspond to printable * characters produce a valid `charCode`, the only exception to this is Enter. * The Tab-key is considered non-printable and does not have a `charCod
(nativeEvent)
| 5266 | * @return {number} Normalized `charCode` property. |
| 5267 | */ |
| 5268 | function getEventCharCode(nativeEvent) { |
| 5269 | var charCode = void 0; |
| 5270 | var keyCode = nativeEvent.keyCode; |
| 5271 | |
| 5272 | if ('charCode' in nativeEvent) { |
| 5273 | charCode = nativeEvent.charCode; |
| 5274 | |
| 5275 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 5276 | if (charCode === 0 && keyCode === 13) { |
| 5277 | charCode = 13; |
| 5278 | } |
| 5279 | } else { |
| 5280 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 5281 | charCode = keyCode; |
| 5282 | } |
| 5283 | |
| 5284 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 5285 | // report Enter as charCode 10 when ctrl is pressed. |
| 5286 | if (charCode === 10) { |
| 5287 | charCode = 13; |
| 5288 | } |
| 5289 | |
| 5290 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 5291 | // Must not discard the (non-)printable Enter-key. |
| 5292 | if (charCode >= 32 || charCode === 13) { |
| 5293 | return charCode; |
| 5294 | } |
| 5295 | |
| 5296 | return 0; |
| 5297 | } |
| 5298 | |
| 5299 | /** |
| 5300 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected