MCPcopy Create free account
hub / github.com/InstantWebP2P/peer-vnc / getKeysym

Function getKeysym

front/include/keyboard.js:167–196  ·  view source on GitHub ↗
(evt)

Source from the content-addressed store, hash-verified

165 // Get the most reliable keysym value we can get from a key event
166 // if char/charCode is available, prefer those, otherwise fall back to key/keyCode/which
167 function getKeysym(evt){
168 var codepoint;
169 if (evt.char && evt.char.length === 1) {
170 codepoint = evt.char.charCodeAt();
171 }
172 else if (evt.charCode) {
173 codepoint = evt.charCode;
174 }
175 else if (evt.keyCode && evt.type === 'keypress') {
176 // IE10 stores the char code as keyCode, and has no other useful properties
177 codepoint = evt.keyCode;
178 }
179 if (codepoint) {
180 var res = keysyms.fromUnicode(substituteCodepoint(codepoint));
181 if (res) {
182 return res;
183 }
184 }
185 // we could check evt.key here.
186 // Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
187 // so we "just" need to map them to keysym, but AFAIK this is only available in IE10, which also provides evt.key
188 // so we don't *need* it yet
189 if (evt.keyCode) {
190 return keysyms.lookup(keysymFromKeyCode(evt.keyCode, evt.shiftKey));
191 }
192 if (evt.which) {
193 return keysyms.lookup(keysymFromKeyCode(evt.which, evt.shiftKey));
194 }
195 return null;
196 }
197
198 // Given a keycode, try to predict which keysym it might be.
199 // If the keycode is unknown, null is returned.

Callers 1

syncKeyEventFunction · 0.85

Calls 2

substituteCodepointFunction · 0.85
keysymFromKeyCodeFunction · 0.85

Tested by

no test coverage detected