* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.
(nativeEvent)
| 5364 | * @return {string} Normalized `key` property. |
| 5365 | */ |
| 5366 | function getEventKey(nativeEvent) { |
| 5367 | if (nativeEvent.key) { |
| 5368 | // Normalize inconsistent values reported by browsers due to |
| 5369 | // implementations of a working draft specification. |
| 5370 | |
| 5371 | // FireFox implements `key` but returns `MozPrintableKey` for all |
| 5372 | // printable characters (normalized to `Unidentified`), ignore it. |
| 5373 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key; |
| 5374 | if (key !== 'Unidentified') { |
| 5375 | return key; |
| 5376 | } |
| 5377 | } |
| 5378 | |
| 5379 | // Browser does not implement `key`, polyfill as much of it as we can. |
| 5380 | if (nativeEvent.type === 'keypress') { |
| 5381 | var charCode = getEventCharCode(nativeEvent); |
| 5382 | |
| 5383 | // The enter-key is technically both printable and non-printable and can |
| 5384 | // thus be captured by `keypress`, no other non-printable key should. |
| 5385 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); |
| 5386 | } |
| 5387 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { |
| 5388 | // While user keyboard layout determines the actual meaning of each |
| 5389 | // `keyCode` value, almost all function keys have a universal value. |
| 5390 | return translateToKey[nativeEvent.keyCode] || 'Unidentified'; |
| 5391 | } |
| 5392 | return ''; |
| 5393 | } |
| 5394 | |
| 5395 | /** |
| 5396 | * @interface KeyboardEvent |
nothing calls this directly
no test coverage detected