* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.
(nativeEvent)
| 4852 | * @return {string} Normalized `key` property. |
| 4853 | */ |
| 4854 | function getEventKey(nativeEvent) { |
| 4855 | if (nativeEvent.key) { |
| 4856 | // Normalize inconsistent values reported by browsers due to |
| 4857 | // implementations of a working draft specification. |
| 4858 | |
| 4859 | // FireFox implements `key` but returns `MozPrintableKey` for all |
| 4860 | // printable characters (normalized to `Unidentified`), ignore it. |
| 4861 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key; |
| 4862 | if (key !== 'Unidentified') { |
| 4863 | return key; |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | // Browser does not implement `key`, polyfill as much of it as we can. |
| 4868 | if (nativeEvent.type === 'keypress') { |
| 4869 | var charCode = getEventCharCode(nativeEvent); |
| 4870 | |
| 4871 | // The enter-key is technically both printable and non-printable and can |
| 4872 | // thus be captured by `keypress`, no other non-printable key should. |
| 4873 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); |
| 4874 | } |
| 4875 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { |
| 4876 | // While user keyboard layout determines the actual meaning of each |
| 4877 | // `keyCode` value, almost all function keys have a universal value. |
| 4878 | return translateToKey[nativeEvent.keyCode] || 'Unidentified'; |
| 4879 | } |
| 4880 | return ''; |
| 4881 | } |
| 4882 | |
| 4883 | /** |
| 4884 | * @interface KeyboardEvent |
nothing calls this directly
no test coverage detected