* `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)
| 5644 | * @return {number} Normalized `charCode` property. |
| 5645 | */ |
| 5646 | function getEventCharCode(nativeEvent) { |
| 5647 | var charCode = void 0; |
| 5648 | var keyCode = nativeEvent.keyCode; |
| 5649 | |
| 5650 | if ('charCode' in nativeEvent) { |
| 5651 | charCode = nativeEvent.charCode; |
| 5652 | |
| 5653 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 5654 | if (charCode === 0 && keyCode === 13) { |
| 5655 | charCode = 13; |
| 5656 | } |
| 5657 | } else { |
| 5658 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 5659 | charCode = keyCode; |
| 5660 | } |
| 5661 | |
| 5662 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 5663 | // report Enter as charCode 10 when ctrl is pressed. |
| 5664 | if (charCode === 10) { |
| 5665 | charCode = 13; |
| 5666 | } |
| 5667 | |
| 5668 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 5669 | // Must not discard the (non-)printable Enter-key. |
| 5670 | if (charCode >= 32 || charCode === 13) { |
| 5671 | return charCode; |
| 5672 | } |
| 5673 | |
| 5674 | return 0; |
| 5675 | } |
| 5676 | |
| 5677 | /** |
| 5678 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected