MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getEventKey

Function getEventKey

code/communication/public/app.js:5528–5555  ·  view source on GitHub ↗

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

(nativeEvent)

Source from the content-addressed store, hash-verified

5526 * @return {string} Normalized `key` property.
5527 */
5528function getEventKey(nativeEvent) {
5529 if (nativeEvent.key) {
5530 // Normalize inconsistent values reported by browsers due to
5531 // implementations of a working draft specification.
5532
5533 // FireFox implements `key` but returns `MozPrintableKey` for all
5534 // printable characters (normalized to `Unidentified`), ignore it.
5535 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
5536 if (key !== 'Unidentified') {
5537 return key;
5538 }
5539 }
5540
5541 // Browser does not implement `key`, polyfill as much of it as we can.
5542 if (nativeEvent.type === 'keypress') {
5543 var charCode = getEventCharCode(nativeEvent);
5544
5545 // The enter-key is technically both printable and non-printable and can
5546 // thus be captured by `keypress`, no other non-printable key should.
5547 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
5548 }
5549 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
5550 // While user keyboard layout determines the actual meaning of each
5551 // `keyCode` value, almost all function keys have a universal value.
5552 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
5553 }
5554 return '';
5555}
5556
5557/**
5558 * @interface KeyboardEvent

Callers

nothing calls this directly

Calls 1

getEventCharCodeFunction · 0.70

Tested by

no test coverage detected