* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.
(nativeEvent)
| 4724 | * @return {string} Normalized `key` property. |
| 4725 | */ |
| 4726 | function getEventKey(nativeEvent) { |
| 4727 | if (nativeEvent.key) { |
| 4728 | // Normalize inconsistent values reported by browsers due to |
| 4729 | // implementations of a working draft specification. |
| 4730 | |
| 4731 | // FireFox implements `key` but returns `MozPrintableKey` for all |
| 4732 | // printable characters (normalized to `Unidentified`), ignore it. |
| 4733 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key; |
| 4734 | if (key !== 'Unidentified') { |
| 4735 | return key; |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | // Browser does not implement `key`, polyfill as much of it as we can. |
| 4740 | if (nativeEvent.type === 'keypress') { |
| 4741 | var charCode = getEventCharCode(nativeEvent); |
| 4742 | |
| 4743 | // The enter-key is technically both printable and non-printable and can |
| 4744 | // thus be captured by `keypress`, no other non-printable key should. |
| 4745 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); |
| 4746 | } |
| 4747 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { |
| 4748 | // While user keyboard layout determines the actual meaning of each |
| 4749 | // `keyCode` value, almost all function keys have a universal value. |
| 4750 | return translateToKey[nativeEvent.keyCode] || 'Unidentified'; |
| 4751 | } |
| 4752 | return ''; |
| 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * @interface KeyboardEvent |
nothing calls this directly
no test coverage detected