Getting key scan code for keyboard shortcuts in order to ignore keyboard layout - is it possible?
-
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.
-
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 :-)
-
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? -
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?
-
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?