tags:

views:

94

answers:

1

Hi,

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

A: 

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.

Johan Buret