Recently, I've been working on a Smart TV application targeted at both LG and Samsung models. I had problems keeping the main code platform independent because the key codes on events generated by the remote controls differed between the vendors. While LG's remote control keys generated fairly sane codes, Samsung's didn't, with the codes for numeric keys seeming completely random (for example, the numeric key 1 has the key code 101
, but 5 has 9
).
I eventually decided to polyfill KeyboardEvent.key, and allow passing a map to the polyfill so that the platform-dependent code could define their own keysets.
The property exposes itself on both the KeyEvent
(non-standard) and KeyboardEvent
(standard) objects and is ideal for use in specific, targeted environments.
This is absolutely amazing, and I plan on using this technique later.
I'll share it here.