* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.
(nativeEvent)
| 5584 | * @return {string} Normalized `key` property. |
| 5585 | */ |
| 5586 | function getEventKey(nativeEvent) { |
| 5587 | if (nativeEvent.key) { |
| 5588 | // Normalize inconsistent values reported by browsers due to |
| 5589 | // implementations of a working draft specification. |
| 5590 | |
| 5591 | // FireFox implements `key` but returns `MozPrintableKey` for all |
| 5592 | // printable characters (normalized to `Unidentified`), ignore it. |
| 5593 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key; |
| 5594 | if (key !== 'Unidentified') { |
| 5595 | return key; |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | // Browser does not implement `key`, polyfill as much of it as we can. |
| 5600 | if (nativeEvent.type === 'keypress') { |
| 5601 | var charCode = getEventCharCode(nativeEvent); |
| 5602 | |
| 5603 | // The enter-key is technically both printable and non-printable and can |
| 5604 | // thus be captured by `keypress`, no other non-printable key should. |
| 5605 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); |
| 5606 | } |
| 5607 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { |
| 5608 | // While user keyboard layout determines the actual meaning of each |
| 5609 | // `keyCode` value, almost all function keys have a universal value. |
| 5610 | return translateToKey[nativeEvent.keyCode] || 'Unidentified'; |
| 5611 | } |
| 5612 | return ''; |
| 5613 | } |
| 5614 | |
| 5615 | /** |
| 5616 | * @interface KeyboardEvent |
nothing calls this directly
no test coverage detected