QTest::keyPress is not returning nativeScanCode
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:
//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
Re: QTest::keyPress is not returning nativeScanCode
You are using artificial events so there is no extended information available for it.
Re: QTest::keyPress is not returning nativeScanCode
Hi,
what is an extended information, is nativeScancode an extended info? plz throw some light on it.
Thanks
vels
Re: QTest::keyPress is not returning nativeScanCode
If you don't know what nativeScancode is, why do you use it?
Re: QTest::keyPress is not returning nativeScanCode
I pretty well know nativeScancode is a unique unsigned int value which is returned on occurrence of a key stroke; from your POV artificial events (QTest::keyPress) don’t give extended information, want to know is nativeScancode one such extended information?
Re: QTest::keyPress is not returning nativeScanCode
Would I write my post like that if it weren't? I assumed you have read the documentation prior to writing your post, maybe I assumed wrong, so - yes, according to what the docs say, native scan code is an extended information provided by the platform. Are you sure you do need this kind of information?
Re: QTest::keyPress is not returning nativeScanCode
yep, I will ignore nativeScanCode and make use of QKeyEvent::key() which returns unicode
Re: QTest::keyPress is not returning nativeScanCode
QKeyEvent::key() doesn't return unicode. It returns enum values.