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

Function getEventCharCode

code/communication/public/app.js:5430–5459  ·  view source on GitHub ↗

* `charCode` represents the actual "character code" and is safe to use with * `String.fromCharCode`. As such, only keys that correspond to printable * characters produce a valid `charCode`, the only exception to this is Enter. * The Tab-key is considered non-printable and does not have a `charCod

(nativeEvent)

Source from the content-addressed store, hash-verified

5428 * @return {number} Normalized `charCode` property.
5429 */
5430function getEventCharCode(nativeEvent) {
5431 var charCode = void 0;
5432 var keyCode = nativeEvent.keyCode;
5433
5434 if ('charCode' in nativeEvent) {
5435 charCode = nativeEvent.charCode;
5436
5437 // FF does not set `charCode` for the Enter-key, check against `keyCode`.
5438 if (charCode === 0 && keyCode === 13) {
5439 charCode = 13;
5440 }
5441 } else {
5442 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
5443 charCode = keyCode;
5444 }
5445
5446 // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
5447 // report Enter as charCode 10 when ctrl is pressed.
5448 if (charCode === 10) {
5449 charCode = 13;
5450 }
5451
5452 // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
5453 // Must not discard the (non-)printable Enter-key.
5454 if (charCode >= 32 || charCode === 13) {
5455 return charCode;
5456 }
5457
5458 return 0;
5459}
5460
5461/**
5462 * Normalization of deprecated HTML5 `key` values

Callers 2

getEventKeyFunction · 0.70
app.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected