cvan / keyboardevent-key-polyfill

polyfill for `KeyboardEvent.prototype.key`
https://cvan.io/keyboardevent-key-polyfill/
Creative Commons Zero v1.0 Universal
47 stars 15 forks source link

Wrong keys on Chromium 37 #15

Open jcubic opened 7 years ago

jcubic commented 7 years ago

I needed to test my project in old Chrome so I've installed Ubuntu 12.04 with chromium 37 that don't have key event property so I needed to use the ployfill and it show wrong keys for keypress:

key z result "F11" key x result "F9" key q result "F2" key w result "F8" key s result "F4" key r result "F3" key t result "F5" key y result "F10" key u result "F6" key p result "F1" key v result "F7" key , result "printScreen" key . result "delete" key ' result "arrowright" key [ result "OS" key ] result "contextMenu"

didn't test with shift.

jcubic commented 7 years ago

the fix is to use String.fromCharCode(e.which) or charCode for keypress,

The key property need to check if the event type is keypress or keydown/up.

If the polyfill don't support keypress then it should return undefined for keypress.