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. Getting key scan code for keyboard shortcuts in order to ignore keyboard layout - is it possible?
Forum Updated to NodeBB v4.3 + New Features

Getting key scan code for keyboard shortcuts in order to ignore keyboard layout - is it possible?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 421 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.
  • Y Offline
    Y Offline
    yonizaf
    wrote on 16 Jun 2025, 19:31 last edited by
    #1

    I posted a bug report for a certain text editor that uses QT, for the fact that keyboard shortcuts (particularly Ctrl+S for saving) don't work if I change the keyboard layout to a non-Latin one.

    Their answer was that it was a QT issue. I did check after that with some other QT based software and found out they did not register keyboard shortcuts either when I switch layout. This was not a problem when I tested non-QT based software.

    My question is, is it possible to programmatically get scan codes from QT in order to ignore keyboard layout for keyboard shortcuts? Or were the maintainers of that software correct when they said it was a QT issue that they can't overcome and I should raise the issue at QT bug tracker?

    Thanks in advance for any response (and sorry if this is the wrong place to ask)

    PS. I use Windows, but any solution should be cross platform I guess.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 17 Jun 2025, 01:54 last edited by
      #2

      You could try to reverse engineer what the Qt scan codes are by inputting the native scan codes, for example:
      create a new empty vanilla QWidgets project,

      in mainwindow.h insert:
      void keyPressEvent(QKeyEvent *event);

      in mainwindow.cpp, in MainWindow::MainWindow() after ui->setupUi(this): insert

      ...
          QTimer::singleShot(50,this,[]
          {
              for (int scancode = 48; (scancode < 127); ++scancode)
              {
                  INPUT ip;
                  ip.type           = INPUT_KEYBOARD;
                  ip.ki.wScan       = 0;
                  ip.ki.time        = 0;
                  ip.ki.dwExtraInfo = static_cast<ULONG>(GetMessageExtraInfo());
      
                  INPUT ipArray[2];
      
                  ip.ki.wVk     = scancode;
                  ip.ki.wScan   = 0;  // try entering a scan code here as well
                  ip.ki.dwFlags = 0;
                  ipArray[0]    = ip;
      
                  ip.ki.dwFlags = KEYEVENTF_KEYUP;
                  ipArray[1]    = ip;
      
                  ::SendInput(2,ipArray,sizeof(ip));
      
                  QCoreApplication::processEvents();
                  QThread::msleep(50);
                  QCoreApplication::processEvents();
              }
          });
      }
      
      void MainWindow::keyPressEvent(QKeyEvent *event)
      {
          qDebug() << event->text() << event->nativeVirtualKey();
      }
      ...
      

      in the above example you'll only get the standard Ascii keyboard values, yoi need to experiment by setting the wScan value as well, but it's a start :-)

      1 Reply Last reply
      1
      • H Offline
        H Offline
        hskoglund
        wrote on 17 Jun 2025, 01:57 last edited by
        #3

        Sorry, forgot you also need to insert these #includes at the top of mainwindow.cpp, after #include "./ui_mainwindow.h" :
        #include "qtimer.h"
        #include "windows.h"
        #include "qthread.h"
        #include "QKeyEvent"
        #include "qdebug.h"

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yonizaf
          wrote on 17 Jun 2025, 06:18 last edited by
          #4

          Thanks.

          In the meantime I found a text editor named tea-qt which behaves correctly (ignoring keyboard layout for shortcuts); Not sure if it uses the method you described or something else. I'll look into it.

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yonizaf
            wrote on 17 Jun 2025, 07:46 last edited by
            #5

            Update: I tested various keyboard layouts (Greek,Arabic,Cyrillic) and they all work fine. So the problem is specific to the keyboard layout I'm using.
            I assume it means this is a Qt bug that I should report? How do I do that?

            J 1 Reply Last reply 17 Jun 2025, 07:50
            0
            • Y yonizaf
              17 Jun 2025, 07:46

              Update: I tested various keyboard layouts (Greek,Arabic,Cyrillic) and they all work fine. So the problem is specific to the keyboard layout I'm using.
              I assume it means this is a Qt bug that I should report? How do I do that?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 17 Jun 2025, 07:50 last edited by
              #6

              @yonizaf said in Getting key scan code for keyboard shortcuts in order to ignore keyboard layout - is it possible?:

              How do I do that?

              https://bugreports.qt.io/secure/Dashboard.jspa

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yonizaf
                wrote on 17 Jun 2025, 09:24 last edited by
                #7

                Thanks. I went there and found a bug that seems relevant: https://bugreports.qt.io/browse/QTBUG-121794
                But it seems stuck, like someone started to work on it a while ago and then nothing.

                Is there something that can be done to make people notice/remember this bug again? or am I better off starting a new one?

                J 1 Reply Last reply 17 Jun 2025, 09:28
                0
                • Y yonizaf
                  17 Jun 2025, 09:24

                  Thanks. I went there and found a bug that seems relevant: https://bugreports.qt.io/browse/QTBUG-121794
                  But it seems stuck, like someone started to work on it a while ago and then nothing.

                  Is there something that can be done to make people notice/remember this bug again? or am I better off starting a new one?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 17 Jun 2025, 09:28 last edited by
                  #8

                  @yonizaf You should not create a new ticket.
                  You commented in the existing, let's see whether this triggers any actions :-)

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  8/8

                  17 Jun 2025, 09:28

                  • Login

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