#include <QtGui>int main(int argc, char *argv[]){ QApplication app(argc, argv); QMainWindow *window = new QMainWindow; QLineEdit *lineEdit= new QLineEdit("The position of cursor is 100,0"); window->setCentralWidget(lineEdit); window->show(); QMouseEvent *pressedLeftMouseButton = new QMouseEvent(QEvent::MouseButtonPress, QPoint(100,0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); app.postEvent( lineEdit, pressedLeftMouseButton); return app.exec();}
QDesktopWidget *desk = new QDesktopWidget; QPoint pos = desk->mapFromGlobal(QCursor::pos()); QMouseEvent *mouse = new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QCoreApplication::postEvent(desk, mouse);
#ifdef Q_WS_WIN#include <w32api.h>#include <windows.h>#endif.......... #ifdef Q_WS_WIN SetCursorPos(pos.x(), pos.y()); Sleep(1); mouse_event(MOUSEEVENTF_MOVE, 0, 0, 0, GetMessageExtraInfo()); Sleep(1); mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()); Sleep(1); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()); #endif