MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / KeyboardEvent

Function KeyboardEvent

src/utils/keyboardEvent.js:113–291  ·  view source on GitHub ↗
(type, dict)

Source from the content-addressed store, hash-verified

111 * @returns
112 */
113export default function KeyboardEvent(type, dict) {
114 let event;
115
116 if (initKeyboardEventType) {
117 event = document.createEvent("KeyboardEvent");
118 } else {
119 event = document.createEvent("Event");
120 }
121
122 let propName;
123 let localDict = {};
124
125 if (!dict.key && (dict.keyCode || dict.which)) {
126 let key = keys[dict.keyCode || dict.which];
127 if (!key) key = String.fromCharCode(dict.keyCode || dict.which);
128 dict.key = key;
129 } else if (dict.key && !dict.which && !dict.keyCode) {
130 let keyCode = Object.keys(keys).find((key) => keys[key] === dict.key);
131 if (!keyCode) keyCode = dict.key.charCodeAt(0);
132 dict.keyCode = keyCode;
133 dict.which = keyCode;
134 }
135
136 for (propName in keyboardEventPropertiesDictionary)
137 if (own(keyboardEventPropertiesDictionary, propName)) {
138 localDict[propName] = ((own(dict, propName) && dict) ||
139 keyboardEventPropertiesDictionary)[propName];
140 }
141
142 const ctrlKey = localDict["ctrlKey"];
143 const shiftKey = localDict["shiftKey"];
144 const altKey = localDict["altKey"];
145 const metaKey = localDict["metaKey"];
146 const altGraphKey = localDict["altGraphKey"];
147
148 const modifiersListArg =
149 initKeyboardEventType > 3
150 ? (
151 (ctrlKey ? "Control" : "") +
152 (shiftKey ? " Shift" : "") +
153 (altKey ? " Alt" : "") +
154 (metaKey ? " Meta" : "") +
155 (altGraphKey ? " AltGraph" : "")
156 ).trim()
157 : null;
158
159 const key = localDict["key"] + "";
160 const char = localDict["char"] + "";
161 const location = localDict["location"];
162 const keyCode =
163 localDict["keyCode"] ||
164 (localDict["keyCode"] = (key && key.charCodeAt(0)) || 0);
165 const charCode =
166 localDict["charCode"] ||
167 (localDict["charCode"] = (char && char.charCodeAt(0)) || 0);
168 const bubbles = localDict["bubbles"];
169 const cancelable = localDict["cancelable"];
170 const repeat = localDict["repeat"];

Callers 3

quickTools.jsFile · 0.85
actionsFunction · 0.85
keyboardHandlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected