3 ms·
Very nice. What API is used to track Shift/Ctrl/Alt keys state?
by ComodoHacker 5y ago
Very nice.
What API is used to track Shift/Ctrl/Alt keys state?
- jarek-foksa 5y agoThere is the standard event.getModifierState() API, but the most reliable solution I found was to listen for "keydown", "keyup", "blur", "pointerdown", "pointermove" and "pointerup" events on the window object and then store the modifier keys state based on the value of event.ctrlKey/altKey/metaKey/shiftKey. You need to listen for the pointer events because some devices such as Wacom tablets do not dispatch proper keyboard events when you press a button that has a modifier key role assigned to it. On Apple devices event.metaKey represents the state of the command key, so in most scenarios you would be storing the state as: let ctrlOrCmd = (isAppleDevice ? event.metaKey : event.ctrlKey);
- steveruizok 5y agoYep, these all come from events.