Shortcut reported to fail on Dvvorak keyboard layout.
Reason
Type uses event.code to resolve physical key pressed, ignoring language and case. E.g. KeyS used for downloading note is actually o charecter on Dvorak.
Possible solutions
- Use
event.key to get resolved key. Need handling of languages and case ☹️
- Use keyboard layouts mapping and resolving.
Example
const LATIN_LAYOUTS = {
qwerty: { 'KeyQ':'q', 'KeyW':'w', 'KeyE':'e', 'KeyR':'r', 'KeyT':'t', 'KeyY':'y' /* ... */ },
dvorak: { 'KeyQ':'\'', 'KeyW':',', 'KeyE':'o', 'KeyR':'e', 'KeyT':'u', 'KeyY':'i' /* ... */ },
colemak: { 'KeyQ':'q', 'KeyW':'w', 'KeyE':'f', 'KeyR':'p', 'KeyT':'g', 'KeyY':'j' /* ... */ }
};
function getLatinCharacter(event, userLayout = 'qwerty') {
const currentKey = event.key;
// If it's already a standard Latin letter/number, use it directly
if (/^[a-z0-9]$/i.test(currentKey)) {
return currentKey.toLowerCase();
}
// Fallback: The user is using a non-Latin language (e.g., Cyrillic, Hebrew)
// Look up what the physical hardware key translates to in the selected Latin layout
const layoutMap = LATIN_LAYOUTS[userLayout];
if (layoutMap && layoutMap[event.code]) {
return layoutMap[event.code];
}
// Return fallback if key is a modifier or special character
return currentKey.toLowerCase();
}
window.addEventListener('keydown', (e) => {
const resolvedChar = getLatinCharacter(e, 'dvorak');
if ((e.ctrlKey || e.metaKey) && resolvedChar === 'o') {
// This executes accurately across languages for a Dvorak user
console.log("Dvorak hotkey triggered!");
}
});
Shortcut reported to fail on Dvvorak keyboard layout.
Reason
Type uses
event.codeto resolve physical key pressed, ignoring language and case. E.g.KeySused for downloading note is actuallyocharecter on Dvorak.Possible solutions
event.keyto get resolved key. Need handling of languages and caseExample