MCPcopy Create free account
hub / github.com/microsoft/SandDance / getEventKey

Function getEventKey

docs/external/js/react-dom.development.js:10020–10048  ·  view source on GitHub ↗

* @param {object} nativeEvent Native browser event. * @return {string} Normalized `key` property.

(nativeEvent)

Source from the content-addressed store, hash-verified

10018 */
10019
10020 function getEventKey(nativeEvent) {
10021 if (nativeEvent.key) {
10022 // Normalize inconsistent values reported by browsers due to
10023 // implementations of a working draft specification.
10024 // FireFox implements `key` but returns `MozPrintableKey` for all
10025 // printable characters (normalized to `Unidentified`), ignore it.
10026 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
10027
10028 if (key !== 'Unidentified') {
10029 return key;
10030 }
10031 } // Browser does not implement `key`, polyfill as much of it as we can.
10032
10033
10034 if (nativeEvent.type === 'keypress') {
10035 var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
10036 // thus be captured by `keypress`, no other non-printable key should.
10037
10038 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
10039 }
10040
10041 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
10042 // While user keyboard layout determines the actual meaning of each
10043 // `keyCode` value, almost all function keys have a universal value.
10044 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
10045 }
10046
10047 return '';
10048 }
10049
10050 /**
10051 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.85

Tested by

no test coverage detected