Open Bug 1841204 Opened 1 year ago Updated 1 year ago

Firefox KeyEvent.keyCode does not match Chrome and Safari, leading to a game site ignoring some keypresses

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

defect

Tracking

()

People

(Reporter: twisniewski, Unassigned)

References

()

Details

For instance, the semicolon key on my MacBook has keycode 59 in Firefox, but the game expects 186, so it completely ignores the keypress. This can be seen with the following data URL test:

data:text/html,<textarea id="text"></textarea><script>document.documentElement.onkeydown=function(e){text.innerHTML=e.keyCode}</script>

Given that this is causing webcompat issues, I think we should revisit this and try to sort out the interop story here.

I think that we cannot align KeyboardEvent.keyCode value by default because it's just an arbitrary value which may identify a key in the keyboard layout. Therefore, web apps need to check UA to make the value meaningful. Therefore, changing the mapping will break other web apps.

(Although I guess that we can create a Gecko specific API to request similar .keyCode value in the document.)

I'm just not convinced that it's better to leave this problem to fester, causing webcompat issues forever, than it is to either remove the API entirely from all browsers (it is deprecated after all) and just break old apps and fix future ones. But I'm not the relative expert here, so I suspect it's probably worth having a discussion with those who are. Maybe we should at least bring this up in the standards fora and see what the Chromium and Webkit folks think?

I think that .keyCode cannot be removed because it's used too widely. The WG considered to create new API .key and .code with giving up to standardize .keyCode. So I think that there is no way to solve it. Once we create a Gecko specific API, extension can call it.

Severity: -- → S3

keyCode is still the most reliable way to detect a keydown event that is part of composition in a way that works on Mac Safari. Which is to say that a lot of apps rely on it and I agree that it is used to widely to remove.

You need to log in before you can comment on or make changes to this bug.