PDA

View Full Version : QTest::keyPress is not returning nativeScanCode



vels
10th May 2010, 09:20
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?




//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

wysota
10th May 2010, 11:24
You are using artificial events so there is no extended information available for it.

vels
10th May 2010, 13:31
Hi,

what is an extended information, is nativeScancode an extended info? plz throw some light on it.

Thanks
vels

wysota
10th May 2010, 16:17
If you don't know what nativeScancode is, why do you use it?

vels
11th May 2010, 04:15
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?

wysota
11th May 2010, 09:56
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?

vels
11th May 2010, 15:03
yep, I will ignore nativeScanCode and make use of QKeyEvent::key() which returns unicode

wysota
11th May 2010, 15:34
QKeyEvent::key() doesn't return unicode. It returns enum values.