* `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)
| 5486 | * @return {number} Normalized `charCode` property. |
| 5487 | */ |
| 5488 | function getEventCharCode(nativeEvent) { |
| 5489 | var charCode = void 0; |
| 5490 | var keyCode = nativeEvent.keyCode; |
| 5491 | |
| 5492 | if ('charCode' in nativeEvent) { |
| 5493 | charCode = nativeEvent.charCode; |
| 5494 | |
| 5495 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 5496 | if (charCode === 0 && keyCode === 13) { |
| 5497 | charCode = 13; |
| 5498 | } |
| 5499 | } else { |
| 5500 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 5501 | charCode = keyCode; |
| 5502 | } |
| 5503 | |
| 5504 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 5505 | // report Enter as charCode 10 when ctrl is pressed. |
| 5506 | if (charCode === 10) { |
| 5507 | charCode = 13; |
| 5508 | } |
| 5509 | |
| 5510 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 5511 | // Must not discard the (non-)printable Enter-key. |
| 5512 | if (charCode >= 32 || charCode === 13) { |
| 5513 | return charCode; |
| 5514 | } |
| 5515 | |
| 5516 | return 0; |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected