Open Bug 1755096 Opened 2 years ago Updated 2 years ago

[UI Events-code] Keyboard event has event.code Backquote and IntlBackslash swapped on macOS with 102/105 ISO keyboard

Categories

(Core :: DOM: Events, defect, P3)

Firefox 96
Unspecified
macOS
defect

Tracking

()

UNCONFIRMED

People

(Reporter: mathieulj, Unassigned, NeedInfo)

References

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0

Steps to reproduce:

window.onkeydown = (e) => console.log("code:", e.code, "key:", e.key);

With an ISO 102/105 keyboard on macOS:

  1. Press the key above tab and immediately to the left of the 1 (/ if using the french Canadian locale)
  2. Press the key immediately to the right of the left shift key (ù if using the french Canadian locale)

With an ANSI 101/104 keyboard still on macOS:
3. Press the key above tab and immediately to the left of the 1 (` if using the Canada English locale)

Actual results:

  1. code: Backquote key: /
  2. code: IntlBackslash key: ù
  3. code: Backquote key: ù

Expected results:

  1. code: IntlBackslash key: /
  2. code: Backquote key: ù
  3. code: Backquote key: ù

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Cocoa' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Widget: Cocoa
Product: Firefox → Core

Could you confirm a couple of things:

  1. Does this reproduce in Safari or Chrome?
  2. Has this worked on previous versions of Firefox?
Severity: -- → S3
Flags: needinfo?(mathieulj)
Priority: -- → P3

Sure thing:

  1. Safari works as expected. Chrome has the same issue, there is a bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=1296783
  2. I'm not sure when it was working before. I've just starting using the event code on a project that made this stand out to me but I did stumble into a closed issue since I created this bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1263302. It would seem to hint that this has been fixed before and may have regressed since but I don't know when.
Flags: needinfo?(mathieulj)

Would you be able to run Mozregression to see when this issue was (re-)introduced?

Flags: needinfo?(mathieulj)

I've run Mozregression and narrowed it down to:

> mozregression --bad 2017-03-01 --good 2017-02-28
 0:03.50 INFO: Got as far as we can go bisecting nightlies...
 0:03.50 INFO: Last good revision: 1bc2ad020aee2830e0a7941f10958dbec108c254 (2017-02-28)
 0:03.50 INFO: First bad revision: 34c6c2f302e7b48e3ad2cec575cbd34d423a9d32 (2017-03-01)
 0:03.50 INFO: Pushlog:
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=1bc2ad020aee2830e0a7941f10958dbec108c254&tochange=34c6c2f302e7b48e3ad2cec575cbd34d423a9d32

This is very interesting because that range includes the "fix" addressing https://bugzilla.mozilla.org/show_bug.cgi?id=1263302. Re-reading that issue now made me realise they were reporting the reverse of what I am seeing. The were seeing the behaviour I would expect and concluded it was a bug.

macOS swaps the IntlBackslash and Backquote keys when the events are coming from an ISO keyboard. With the current state of the code base, pressing the ` key on my ANSI keyboard produces event.key === ` and event.code === Backquote whereas pressing the ` key on my ISO keyboard produces event.key === ` and event.code === IntlBackslash. Surely both these standard apple keyboards should produce the same event.code to match the typed out character?

Flags: needinfo?(mathieulj)

Masayuki-san, could you weigh in here? See comment 5. Thank you!

Flags: needinfo?(masayuki)

Sounds like that macOS changed the behavior so that I guess that we need to check older macOS behavior too.

Component: Widget: Cocoa → DOM: Events
OS: Unspecified → macOS
Hardware: Unspecified → x86_64
See Also: → 1263302
Summary: Keyboard event has event.code Backquote and IntlBackslash swapped on macOS with 102/105 ISO keyboard → [UI Events-code] Keyboard event has event.code Backquote and IntlBackslash swapped on macOS with 102/105 ISO keyboard

According to the timestamp, at least OS X 10.11 El Capitan and macOS Sierra 10.12 had the bug.

Looks like that the expected result is wrong for 102/105 keyboard layout. The key left of Digit1 should be Backquote and the key right of ShiftLeft should be IntlBackslash. Could you check the relation of STR, actual results and expected results in comment 0?

Flags: needinfo?(masayuki) → needinfo?(mathieulj)

When I connect JIS 106 (for PC)/ANSI 101 keyboard (Apple)/102 keyboard (for PC) to macOS Monterey whose active keyboard layout is Canadian French CSA, I get same result. The key left of Digit1 is Backquote.

Ah, I use Intel Mac. If it's related to keyboard driver of macOS, the CPU architecture may change the behavior.

Hardware: x86_64 → Unspecified
You need to log in before you can comment on or make changes to this bug.