* `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)
| 4626 | * @return {number} Normalized `charCode` property. |
| 4627 | */ |
| 4628 | function getEventCharCode(nativeEvent) { |
| 4629 | var charCode = void 0; |
| 4630 | var keyCode = nativeEvent.keyCode; |
| 4631 | |
| 4632 | if ('charCode' in nativeEvent) { |
| 4633 | charCode = nativeEvent.charCode; |
| 4634 | |
| 4635 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 4636 | if (charCode === 0 && keyCode === 13) { |
| 4637 | charCode = 13; |
| 4638 | } |
| 4639 | } else { |
| 4640 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 4641 | charCode = keyCode; |
| 4642 | } |
| 4643 | |
| 4644 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 4645 | // report Enter as charCode 10 when ctrl is pressed. |
| 4646 | if (charCode === 10) { |
| 4647 | charCode = 13; |
| 4648 | } |
| 4649 | |
| 4650 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 4651 | // Must not discard the (non-)printable Enter-key. |
| 4652 | if (charCode >= 32 || charCode === 13) { |
| 4653 | return charCode; |
| 4654 | } |
| 4655 | |
| 4656 | return 0; |
| 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected