Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Questions about QKeyEvent's native scan code
Servers for Qt installer are currently down

Questions about QKeyEvent's native scan code

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 998 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megamouse
    wrote on 22 Jun 2020, 18:02 last edited by Megamouse
    #1

    Hi,

    I am currently trying to move away from the limited Qt::Key to native scan codes, because that way I can perfectly track all the pressed keys in a set, without having to care about modifiers and sequences (that I don't need in my use case anyway).

    The only thing I'm having trouble with is mapping the existing Qt::Keys to a native scan code outside of keyPressEvent.

    I tried creating a QKeyEvent(QEvent::Type::KeyPress, key, Qt::KeyboardModifier::NoModifier) and calling nativeScanCode() on it, but this always returns 0, while calling the same function on a QKeyEvent passed to a keyPressEvent returns the correct value.

    To explain:
    I am saving a key config of a game to a file, using QKeySequence(keyEvent->key()).toString(QKeySequence::NativeText) in order to make it readable for the user, and then load the Qt::Key it with QKeySequence(name)[0]. I now simply need to convert these strings or keys to a native scan code.

    Alternatively I could save the native scan code, but then I'd have to convert that to a readable string in the gui.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 28 Jun 2020, 04:46 last edited by
      #2

      The Qt Key Event is going to map to the native windowing system. So, your mapping is going to be dependent upon the keysym definitions of that windowing system. Windows, MAC, and Unix/X11 may have different mechanisms for receving keyboard input. Don't plan on your hack to be portable.

      1 Reply Last reply
      0

      1/2

      22 Jun 2020, 18:02

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved