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. How to get nativeVirtualKey for arrow keys [SOLVED]

How to get nativeVirtualKey for arrow keys [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.7k Views
  • 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.
  • D Offline
    D Offline
    Dani
    wrote on last edited by Dani
    #1

    Hi.
    I need to find a method how to get nativeVirtualKey for arrow keys.
    I've tried so: QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey()
    but it's not work.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dani said:
      hi and welcome

      Did you test with quint32 QKeyEvent::nativeScanCode() const ?

      D 1 Reply Last reply
      1
      • mrjjM mrjj

        @Dani said:
        hi and welcome

        Did you test with quint32 QKeyEvent::nativeScanCode() const ?

        D Offline
        D Offline
        Dani
        wrote on last edited by
        #3

        @mrjj You mean this?
        QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();
        This is not works too - this statement returns 0.

        mrjjM 1 Reply Last reply
        0
        • D Dani

          @mrjj You mean this?
          QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();
          This is not works too - this statement returns 0.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @mrjj said:
          No its another function than native virtualkey.

          void keyPressEvent ( QKeyEvent* ke )
              {
                  int nativeCode = ke->nativeScanCode();
                  qDebug() << nativeCode;
          
             }
          

          lists values for arrow keys. Not sure sure if it is the one you want.

          For test I also tried nativeVirtualKey and it returns
          37,38,39,40 for arrows which seems to be VK_LEFT etc.

          From this line I assume you try to use it as lookup call ?QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();

          You are not catching a real key even but try into to convert from qt::key_up to sort of like VK_ARROWUP ?

          I do not think this can work since the real event provides the sym key and here you just construct a fake one so this info is not there.

          D 1 Reply Last reply
          1
          • mrjjM mrjj

            @mrjj said:
            No its another function than native virtualkey.

            void keyPressEvent ( QKeyEvent* ke )
                {
                    int nativeCode = ke->nativeScanCode();
                    qDebug() << nativeCode;
            
               }
            

            lists values for arrow keys. Not sure sure if it is the one you want.

            For test I also tried nativeVirtualKey and it returns
            37,38,39,40 for arrows which seems to be VK_LEFT etc.

            From this line I assume you try to use it as lookup call ?QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();

            You are not catching a real key even but try into to convert from qt::key_up to sort of like VK_ARROWUP ?

            I do not think this can work since the real event provides the sym key and here you just construct a fake one so this info is not there.

            D Offline
            D Offline
            Dani
            wrote on last edited by
            #5

            @mrjj Thank for reply.
            I'm sorry. I meant this in last message: QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeScanCode(); It had not worked too, and now I almost understand why. Explain please, what is sym key? Symbol key?
            I don't know am I right, but I think that it hadn't worked because real event calls this constructor with ready nativeVirtualKey and scanCode:
            QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1)
            I thought, this codes are calculating somewhere In constructor, but as i see - they need to be listed when constructor is called.

            I get good nativeVirtualKey in keyboardEvent and it also equals 37, 38, 39, 40, but I wanted to get constants anywhere else and not to use Windows constants. Is there any possible way?

            mrjjM 1 Reply Last reply
            0
            • D Dani

              @mrjj Thank for reply.
              I'm sorry. I meant this in last message: QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeScanCode(); It had not worked too, and now I almost understand why. Explain please, what is sym key? Symbol key?
              I don't know am I right, but I think that it hadn't worked because real event calls this constructor with ready nativeVirtualKey and scanCode:
              QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1)
              I thought, this codes are calculating somewhere In constructor, but as i see - they need to be listed when constructor is called.

              I get good nativeVirtualKey in keyboardEvent and it also equals 37, 38, 39, 40, but I wanted to get constants anywhere else and not to use Windows constants. Is there any possible way?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Dani
              Hi
              yes sym = symbol key. bad name. its more like native key value.
              The reason its not working is that the native/os/nativeVirtualKey is part of the real os event and added to the
              QKeyEvent class when a real OS event happens.
              So I do not think creating one will contain the info you want.

              I have never seen such function but Qt is big so there might be something.
              You might be able to borrow some from KDE
              http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/kkeyserver__win_8cpp_source.html

              Can I ask why you want native values and cant just use Qt::Key_xx ?

              D 1 Reply Last reply
              1
              • mrjjM mrjj

                @Dani
                Hi
                yes sym = symbol key. bad name. its more like native key value.
                The reason its not working is that the native/os/nativeVirtualKey is part of the real os event and added to the
                QKeyEvent class when a real OS event happens.
                So I do not think creating one will contain the info you want.

                I have never seen such function but Qt is big so there might be something.
                You might be able to borrow some from KDE
                http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/kkeyserver__win_8cpp_source.html

                Can I ask why you want native values and cant just use Qt::Key_xx ?

                D Offline
                D Offline
                Dani
                wrote on last edited by
                #7

                @mrjj With keyboardEvent I store pressed keys.I need to react on English and non-English keyboard the same. So I wanted to use nativeVirtualKey to perform the same reaction on same keys (but in different language). But it hadn't worked for arrow keys: Qt::Key_Up has value 16 777 235. So I needed to do something with that.

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  hi
                  oh, i thought Qt would send same Qt::Key_xx
                  regardless of the actual keyboard.

                  Good to know it wont.

                  1 Reply Last reply
                  0

                  • Login

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