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