0

I would like to implement hotkeys in a web application using the .code property of the received keyboard events, as those seem to be the correct way to produce layout-independent bindings. The only issue is that while I'm completely fine with ignoring the produced symbols under the hood, I would still like to show the user the keyboard hints that they need to press adjusted to their own layouts.

For examply I would like to keep the shortcut for Undo to be the the left shift and the key right next to it ("KeyZ", keycode 0x002C), but on for example the Hungarian layout (see below), that key produces the symbol Y, so I would like to show the user the following hint: "Undo (Ctrl + Y)".

hungarian-keyboard-layout

Is that achievable in some way? I tried searching for a browser API, that would map modifiers and keycodes to symbols on the currently active layout, but couldn't find any, and I couldn't come up with any possible workaround either.

Isti115
  • 2,418
  • 3
  • 29
  • 35

1 Answers1

0

After searching around again and again for several days trying to figure something out (experimenting with synthetic keyboard events and such...) I have finally came across an attempt towards a possible solution: https://wicg.github.io/keyboard-map/#keyboardlayoutmap-interface

The provided example on MDN is exactly the same use case I was looking for: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardLayoutMap#examples

Sadly it is not currently available in Firefox, and the resources that this answer points to make it seem like there's a pretty low chance of it getting implemented anytime soon: https://stackoverflow.com/a/69378454/1831096

Isti115
  • 2,418
  • 3
  • 29
  • 35