* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.
(nativeEvent)
| 5742 | * @return {string} Normalized `key` property. |
| 5743 | */ |
| 5744 | function getEventKey(nativeEvent) { |
| 5745 | if (nativeEvent.key) { |
| 5746 | // Normalize inconsistent values reported by browsers due to |
| 5747 | // implementations of a working draft specification. |
| 5748 | |
| 5749 | // FireFox implements `key` but returns `MozPrintableKey` for all |
| 5750 | // printable characters (normalized to `Unidentified`), ignore it. |
| 5751 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key; |
| 5752 | if (key !== 'Unidentified') { |
| 5753 | return key; |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | // Browser does not implement `key`, polyfill as much of it as we can. |
| 5758 | if (nativeEvent.type === 'keypress') { |
| 5759 | var charCode = getEventCharCode(nativeEvent); |
| 5760 | |
| 5761 | // The enter-key is technically both printable and non-printable and can |
| 5762 | // thus be captured by `keypress`, no other non-printable key should. |
| 5763 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); |
| 5764 | } |
| 5765 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { |
| 5766 | // While user keyboard layout determines the actual meaning of each |
| 5767 | // `keyCode` value, almost all function keys have a universal value. |
| 5768 | return translateToKey[nativeEvent.keyCode] || 'Unidentified'; |
| 5769 | } |
| 5770 | return ''; |
| 5771 | } |
| 5772 | |
| 5773 | /** |
| 5774 | * @interface KeyboardEvent |
nothing calls this directly
no test coverage detected