PDA

View Full Version : how to Simulate the keyboard press



duduqq
9th August 2008, 05:33
when i press one button on the widget ,I want to Simulate the keyboard like press the key "PgDn" ,it will make the IE page down ,how can i do that,dose it must use the Xlib to do that ,and can you give me some code .

spirit
9th August 2008, 09:13
try this code.


QKeyEvent key(QEvent::KeyPress, Qt::Key_PageDown, Qt::NoModifier); QApplication::sendEvent(widget_reciver, &key);
if (key.isAccepted()) {
//everything is ok
} else {
//something wrong
}

read http://doc.trolltech.com/4.4/qcoreapplication.html#sendEvent and QKeyEvent for detailes.

duduqq
9th August 2008, 14:54
try this code.


QKeyEvent key(QEvent::KeyPress, Qt::Key_PageDown, Qt::NoModifier); QApplication::sendEvent(widget_reciver, &key);
if (key.isAccepted()) {
//everything is ok
} else {
//something wrong
}

read http://doc.trolltech.com/4.4/qcoreapplication.html#sendEvent and QKeyEvent for detailes.
thanks
but in My app the widget_reciver is the FireFox or the openOffice or other app is not the Qt's QWidget.
I don't know how to do that .

duduqq
9th August 2008, 17:50
I find the exam in
http://www.qt-apps.org/content/show.php/QVKeyboard?content=77983