Closed Girgias closed 3 years ago
On a keydown
event e.code
will return KeyB
and KeyA
if either the "A" or "B" keys are pressed on the keyboard. This works in latest Chrome, Firefox and Safari. If you look at event.key
you'll see "b" and "a" or "B" and "A" depending on whether you held down shift or have caps-lock enabled.
Internet Explorer and Edge don't support e.code
in the same way, but in light of Edge moving to Chromium now... I'm debating if a workaround matters? There is a polyfill keyboard events that would make e.code
behave consistently across browsers, but I'd rather avoid any external dependencies or code bloat for what I suspect is a really small % of use cases and only going to shrink...
Fair enough also is it's just for an easter egg if it doesn't work on some browsers it doesn't really matter. Will close the issue
Actually gonna reopen the issue just did a quick test on Firefox latest version and it seems like the e.code is keyboard layout dependent. On my french AZERTY keyboard pressing A will result in a 'KeyQ' event being launched
(EDIT: however this is maybe a FF bug) (EDIT2: This is not a FF bug it's something intended by the spec. See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code )
@Girgias That's a very interesting catch! This seems like an good argument for using key
instead of code.
I'll take a look at updating the code in the 2.0 branch. If you feel like tackling it please feel free to submit a pull request!
Not the best in JS but that should be doable will see if I manage.
In the source file shouldn't line 13
sequence: ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'KeyB', 'KeyA'] ,
be equal tosequence: ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'],
?