开发者

QTest::keyPress is not returning nativeScanCode

开发者 https://www.devze.com 2022-12-29 14:19 出处:网络
I am simulating F1 key using QTest::keyPress() method to test keypress event, on simulation of F1 key when i check for nativeScanCode, it returns 0 value. can any one help?

I am simulating F1 key using QTest::keyPress() method to test keypress event, on simulation of F1 key when i check for nativeScanCode, it returns 0 value. can any one help?

//Code snippet开发者_如何学编程
//To simulate F1 key press
QTest::keyPress(&kboard, Qt::Key_F1);

//To check keypress Event
void keyboard::keyPressEvent(QKeyEvent* ke) {
if ( ke->type() == QEvent::KeyPress ) {
QKeyEvent* key_event = static_cast<QKeyEvent *>(ke);
//To check F1 key simulation
if (key_event->key() == Qt::Key_F1) {
    int nativeCode = key_event->nativeScanCode();
    qDebug()<< nativeCode <<endl;
}
  }
}

Thanks,

vels


http://doc.qt.nokia.com/4.4/qkeyevent.html#nativeScanCode

Returns the native scan code of the key event. If the key event does not contain this data 0 is returned.

Note: The native scan code may be 0, even if the key event contains extended information.

I don't know much about QT, but I assume that QTest::keyPress doesn't fill all infos. Testing this event code with a real F1 keystroke might work better.

0

精彩评论

暂无评论...
验证码 换一张
取 消