Ignore keyup events for modifier keys

This commit is contained in:
Joseph Montanaro 2023-09-12 15:27:15 -07:00
parent 03d164c9d3
commit a7df7adc8e

View File

@ -7,6 +7,7 @@
const id = Math.random().toString().slice(2);
const dispatch = createEventDispatcher();
const modifierKeys = new Set(['Alt', 'AltGraph', 'Control', 'Fn', 'FnLock', 'Meta', 'Shift', 'Super', ]);
let listening = false;
function listen() {
@ -20,12 +21,15 @@
}
function setKeybind(event) {
console.log(event);
// separate events fire for modifier keys, even when they are combined with a regular key
if (modifierKeys.has(event.key)) return;
let keys = [];
if (event.ctrlKey) keys.push('ctrl');
if (event.altKey) keys.push('alt');
if (event.metaKey) keys.push('meta');
if (event.shiftKey) keys.push('shift');
if (event.ctrlKey) keys.push('Ctrl');
if (event.altKey) keys.push('Alt');
if (event.metaKey) keys.push('Meta');
if (event.shiftKey) keys.push('Shift');
// capitalize
keys.push(event.key);
value.keys = keys.join('+');