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

On Windows QtWebEngine, right ctrl/alt sends left ctrl/alt KeyboardEvent.code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.15.1
    • 5.15.0
    • WebEngine
    • None
    • Windows 10 x64
      Qt 5.15.0, accompanying QtWebEngine
    • Windows
    • a2a19a6965601ced75e3e48b2bf618ba2bdbd29e (qt/qtwebengine/dev)

    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 Windows, in QtWebEngine, if you press right ctrl/alt, the resulting JS DOM "KeyboardEvent.code" value is left ctrl/alt. You can view keyboard events at W3C's Keyboard Event Viewer.

      On Windows, WM_KEYDOWN delivers a 9-bit flag+scancode between 0x000 and 0x1ff, in bits 16-23 and 24. For some reason, when Chromium receives a WM_KEYDOWN message with an extended key (like right ctrl/alt and both win keys), it explicitly replaces the 0x100 bit with 0xe000 (presumably to match hardware scancodes). And DomCode expects extended keys to be in that format (link).

      However, QtWebEngine's nativeKeyCodeForKeyEvent() fails to perform that transformation.

      When QtWebEngine calls ui::KeycodeConverter::NativeKeycodeToDomCode(), the function fails to find the appropriate code for the native key. So "dom_code" is set to a value synthesized from "windows_key_code". Which is almost right, and works for pageup/pagedown... but it replaces right ctrl/alt with left ctrl/alt, and both Windows keys with left windows key...

      In my fork, to fix this issue, I made `nativeKeyCodeForKeyEvent(const QKeyEvent *ev)` apply this transformation on Windows.

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

      Attachments

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

        Activity

          People

            qt_webengine_team Qt WebEngine Team
            nyanpasu64 Nyan Pasu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes