* `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)
| 4717 | * @return {number} Normalized `charCode` property. |
| 4718 | */ |
| 4719 | function getEventCharCode(nativeEvent) { |
| 4720 | var charCode = void 0; |
| 4721 | var keyCode = nativeEvent.keyCode; |
| 4722 | |
| 4723 | if ('charCode' in nativeEvent) { |
| 4724 | charCode = nativeEvent.charCode; |
| 4725 | |
| 4726 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 4727 | if (charCode === 0 && keyCode === 13) { |
| 4728 | charCode = 13; |
| 4729 | } |
| 4730 | } else { |
| 4731 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 4732 | charCode = keyCode; |
| 4733 | } |
| 4734 | |
| 4735 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 4736 | // report Enter as charCode 10 when ctrl is pressed. |
| 4737 | if (charCode === 10) { |
| 4738 | charCode = 13; |
| 4739 | } |
| 4740 | |
| 4741 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 4742 | // Must not discard the (non-)printable Enter-key. |
| 4743 | if (charCode >= 32 || charCode === 13) { |
| 4744 | return charCode; |
| 4745 | } |
| 4746 | |
| 4747 | return 0; |
| 4748 | } |
| 4749 | |
| 4750 | /** |
| 4751 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected