Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useHotkeys inaccurately infers characters, breaking alternate layouts, hurting accessibility and localisation #6693

Open
ollie299792458 opened this issue Feb 1, 2024 · 0 comments

Comments

@ollie299792458
Copy link
Member

ollie299792458 commented Feb 1, 2024

Environment

  • Package version(s): >=5.0.2
  • Operating System: All
  • Browser name and version: All

Code Sandbox

Link to a minimal repro: https://blueprintjs.com/docs/#core/hooks/use-hotkeys (the keyboard)

Steps to reproduce

  1. Set your keyboard layout such that it doesn't match your physical keyboard layout
  2. Try to use the piano with a key where both the physical key and the mapped character appear on the piano
  3. The key based on the physical key value lights up, not based on the mapped character

Actual behavior

useHotkeys makes use of code to infer which character a user has pressed, Mozilla's documentation states this is not correct usage: "Be aware, however, that you can't use the value reported by KeyboardEvent.code to determine the character generated by the keystroke".

Currently users with keyboard layouts that don't match their physical keyboard are unable to use hotkeys effectively, as hotkeys will often end up colliding with browser shortcuts. For example, if an application has a cmd+b hotkey a user of Left-handed DVORAK wouldn't be able to use cmd+w to quit the tab, and would instead end up triggered the cmd+b hotkey.

This has localisation impact (French user typing in AZERTY on a US keyboard) and accessibility impact (one handed user typing using a one handed DVORAK layout).

Expected behavior

key should be used when the character generated instead of the specific key position is desired. This way the users keyboard layout is respected, this is the approach shared by most software, websites, and operating systems, the main exceptions are some video games (but most support in application key remapping of some form)

Possible solution

The issues with useHotkeys raised in #6257 would return if a simple switch back to key was done. However, from my research, key combinations using option/alt are reasonably rare in web applications. Additionally, alt key combinations risk conflicting with users wanting to use alt codes to type special characters, so maybe we should consider not supporting alt based combinations.

Some nuance is likely needed with handling modifier keys, thoughts here:

  • Use getModifierState to handle a few common modifier keys
  • Find an appropriately licensed hotkey library to incorporate that deals with this issue already.
  • The experimental getLayoutMap could be used
  • Hard part will likely be ensuring it isn't a breaking change for those with keyboard layouts that match their keyboards
@adidahiya adidahiya changed the title sseHotkeys inaccurately infers characters, breaking alternate layouts, hurting accessibility and localisation useHotkeys inaccurately infers characters, breaking alternate layouts, hurting accessibility and localisation Feb 1, 2024
@adidahiya adidahiya added this to To do in UX paper cuts via automation Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants