View Full Version : How to post a key event to another application

23rd June 2006, 13:50
Hi all, I placed some text in my QClipboard (Win32, Qt 4.1.0) and I would like to automatically paste it to the desktop window that has focus at the time. I tried to send a Ctrl+V key event as follows but with no success:

QDesktopWidget* l_desktop = QApplication::desktop();
QWidget* l_desktopWindowWithFocus = l_desktop->focusWidget();
QApplication::postEvent(l_desktopWindowWithFocus, new QKeyEvent(QEvent::KeyPress, Qt::Key_V, Qt::ControlModifier));

The problem was that l_desktop->focusWidget(); returned NULL.

Is what I want to do possible with Qt?

thanks a lot,

23rd June 2006, 14:09
Ok, I found that it is not possible. I have to use a platform specific solution.