Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85660

On macOS QtWebEngine with non-QWERTY keyboard layouts, pressing "a" key sends wrong KeyboardEvent.code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.0, 6.2.3
    • WebEngine
    • None
    • macOS 10.15 on VMware Workstation 15 Player
      Qt 5.15.0 and accompanying QtWebEngine
    • macOS

    Description

      In JS, "KeyboardEvent.code" is intended to reflect the physical location of a key, with name determined by its label on a QWERTY keyboard.

      Bug: on macOS, in QtWebEngine, if you press the key labeled "a" on QWERTY keyboards, the resulting JS DOM "KeyboardEvent.code" value is based on the keyboard layout, rather than the physical position. You can view keyboard events at W3C's Keyboard Event Viewer.

      Why does this happen? If you press the "QWERTY a key", QKeyEvent::nativeVirtualKey() has a valid value of 0. Unfortunately, WebEventFactory::toWebKeyboardEvent(QKeyEvent *ev) assumes any "native_key_code" with a value of 0 is invalid, and subsequently overwrites "dom_code" with a value synthesized from "windows_key_code".

      To make things worse, pressing modifier keys also creates a QKeyEvent with nativeVirtualKey() == nativeScanCode() == 0. (This is already reported at QTBUG-69608.)

      In my fork, to fix this issue, I made `nativeKeyCodeForKeyEvent(const QKeyEvent *ev)` return a std::optional<quint32>. To tell apart modifiers and "a" keys, I only returned a value if nativeScanCode() was nonzero (it's always 1 for regular keyboard events on macOS).

      Link to my fork at https://github.com/nyanpasu64/qkeycode/blob/master/src/qkeycode/qkeycode.cpp#L168-L191. Permalink at https://github.com/nyanpasu64/qkeycode/blob/9480639/src/qkeycode/qkeycode.cpp#L168-L191 (link may break if I force push).

      To merge my fork into qtwebengine, you'd probably have to replace std::optional with something compatible with C++03/11, keep the new variable nativeKeyCode, then assign "webKitEvent.native_key_code = ui::KeycodeConverter::InvalidNativeKeycode();" if nativeKeyCode is empty.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mibrunin Michael Bruning
            nyanpasu64 Nyan Pasu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes