* `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)
| 4754 | * @return {number} Normalized `charCode` property. |
| 4755 | */ |
| 4756 | function getEventCharCode(nativeEvent) { |
| 4757 | var charCode = void 0; |
| 4758 | var keyCode = nativeEvent.keyCode; |
| 4759 | |
| 4760 | if ('charCode' in nativeEvent) { |
| 4761 | charCode = nativeEvent.charCode; |
| 4762 | |
| 4763 | // FF does not set `charCode` for the Enter-key, check against `keyCode`. |
| 4764 | if (charCode === 0 && keyCode === 13) { |
| 4765 | charCode = 13; |
| 4766 | } |
| 4767 | } else { |
| 4768 | // IE8 does not implement `charCode`, but `keyCode` has the correct value. |
| 4769 | charCode = keyCode; |
| 4770 | } |
| 4771 | |
| 4772 | // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) |
| 4773 | // report Enter as charCode 10 when ctrl is pressed. |
| 4774 | if (charCode === 10) { |
| 4775 | charCode = 13; |
| 4776 | } |
| 4777 | |
| 4778 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. |
| 4779 | // Must not discard the (non-)printable Enter-key. |
| 4780 | if (charCode >= 32 || charCode === 13) { |
| 4781 | return charCode; |
| 4782 | } |
| 4783 | |
| 4784 | return 0; |
| 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Normalization of deprecated HTML5 `key` values |
no outgoing calls
no test coverage detected