Hotkey Recorder records wrong key format #104
TanStack Hotkeys version#
0.7.1
Framework/Library version#
Svelte 0.9.1
Describe the bug and the steps to reproduce it#
When using createHotkeyRecorder, the recorded hotkey is using the wrong format.
When I record a Shift+1 hotkey, it captures a Shift+! instead. Same happens for the option key; Option+1 captures ⌥ ¡.
Using the validateHotkey function, validateHotkey('Shift+1') is valid and has no errors and warnings, but validateHotkey('Shift+!') has this warning: "Unknown key: '!'. This may still work but won't have type-safe autocomplete."
Expectation#
Recording Shift+1 should return Shift+1, not Shift+!
Code#
<script lang="ts">
import { createHotkeyRecorder, formatForDisplay, validateHotkey } from '@tanstack/svelte-hotkeys';
const recorder = createHotkeyRecorder({
onRecord: (hotkey) => {
console.log({
hotkey,
recorded: recorder.recordedHotkey,
formatForDisplay: formatForDisplay(hotkey),
});
},
});
console.log('validateHotkey("Shift+1")', validateHotkey('Shift+1'));
console.log('validateHotkey("Shift+!")', validateHotkey('Shift+!'));
</script>
<button
onclick={() => {
recorder.startRecording();
}}
>
Record
</button>
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
Screenshots or Videos (Optional)#
https://github.com/user-attachments/assets/2097c392-1c24-4586-8656-9ab5d1e9fa7a
Do you intend to try to help solve this bug with your own PR?#
No, because I do not have time to dig into it
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
KevinVandy closed this
Sign in to join this conversation.
I've investigated it a little bit, here's what I found:
The
parseKeyboardEventcallsnormalizeKeyNameand passesevent.keyas the parameter. On my keyboard, this will be!anytime I press Shift+1, but the code isDigit1.Maybe
normalizeKeyNameshould also receive thecodeparameter and parse Digit* code as a number but I don't know the implications of doing it, since this function is used on a lot of places and there are a lot of different keyboard layouts that could have different behaviors.