* `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 `c
(nativeEvent)
| 9920 | * @return {number} Normalized `charCode` property. |
| 9921 | */ |
| 9922 | function getEventCharCode(nativeEvent) { |
| 9923 | var charCode; |
| 9924 | var keyCode = nativeEvent.keyCode; |
| 9925 | |
| 9926 | if ('charCode' in nativeEvent) { |
| 9927 | charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 9928 | |
| 9929 | if (charCode === 0 && keyCode === 13) { |
| 9930 | charCode = 13; |
| 9931 | } |
| 9932 | } else { |
| 9933 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 9934 | charCode = keyCode; |
| 9935 | } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 9936 | // report Enter as charCode 10 when ctrl is pressed. |
| 9937 | |
| 9938 | |
| 9939 | if (charCode === 10) { |
| 9940 | charCode = 13; |
| 9941 | } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 9942 | // Must not discard the (non-)printable Enter-key. |
| 9943 | |
| 9944 | |
| 9945 | if (charCode >= 32 || charCode === 13) { |
| 9946 | return charCode; |
| 9947 | } |
| 9948 | |
| 9949 | return 0; |
| 9950 | } |
| 9951 | |
| 9952 | /** |
| 9953 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected