Re: [w3c/uievents] Need property which gives the (base) unmodified key (#247)

@garykac Gary, thank you for your response.

I have made a prototype reimplementation of my app using the KeyboardMap API. Generally speaking, it does the trick. If I match my bindings based on `KeyboardMap.get(event.code)`, I can detect something like AltGr+Z, regardless of what the value of `.key` is for the current layout. Even though I had to make some workarounds, the API is certainly more predictable than relying on `keyCode`, which is nice.

However, I think adding a **`.baseKey`** property to `KeyboardEvent` **would still be a good idea**. The KeyboardMap solution forces me to load the whole keyboard map ahead of time, which magnifies privacy implications. For example, some browsers may decide that explicit user consent is required for such an operation. I really wouldn't want to degrade the experience of my users with a confusing popup. There's way too many of those already.

Other browsers may refuse to implement the API altogether. I see Apple [has already decided](https://github.com/WICG/keyboard-map/issues/30) the API is too invasive. I don't agree with that decision, but something like `.baseKey` would have a **bigger chance of gaining acceptance**, because it only leaks information when the user types something into the website (it cannot just be some banner ad). It does not leak much more information that what can already be gleaned from KeyboardEvent properties.

Another, minor issue is that, unlike `.baseKey`, KeyboardMap requires the page to monitor layout changes by means of the `layoutchange` event. This is extra work (albeit not very much), but more importantly, `layoutchange` isn't implemented by any browser yet. 

On the other hand, I do appreciate that KeyboardMap has one advantage over `.baseKey`. For example, KeyboardMap allows me to detect an AZERTY layout before the user types anything. I can then adjust my UI (e.g. the onscreen keyboard, the displayed shortcut hints) accordingly to create a customized experience. I'm not sure if I would actually use this capability, but it's nice to know it's there.

I'd be very interested in hearing your thoughts.



PS. In the course of my testing, I have identified several problems with how KeyboardMap is specified. I will submit those issues to the KeyboardMap github shortly. I hope you'll find my suggestions helpful!

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/uievents/issues/247#issuecomment-557327129

Received on Friday, 22 November 2019 00:02:34 UTC