PDA

View Full Version : Automate Mousse click event



kuppan-j
1st April 2013, 17:40
Mouse button clicki am trying to create an automatic mouse click event at a particular co ordinate.

This source code moves the mouse pointer to the co ordinate region but it is not clicking.

please help me to solve this problem or suggest any new idea to automate mouse click event.

Note: i am using QT 3.0.3



i am seek of thie please help me



void mMouseClickFunction()
{

QWidget *d = QApplication::desktop()->screen();
int w=d->width(); // returns desktop width
int h=d->height();
printf("w=%d\nh=%d\n",w,h);
int x,y;
printf("Enter the points...\n");
scanf("%d%d",&x,&y);
QApplication::desktop()->cursor().setPos(x,y);
QPoint pt(x,y);
std::cout << pt.x() << " " << pt.y() << std::endl;
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, pt,Qt::LeftButton, 0);
QApplication::sendEvent(d, e);
std::cout << "in contentsMousePressEvent" \
<< e->x() << " " << e->y() << std::endl;
QMouseEvent *p = new QMouseEvent(QEvent::MouseButtonRelease, pt,Qt::LeftButton, 0);
QApplication::sendEvent(d, p);
std::cout << "in contentsMouseReleaseEvent" \
<< p->x() << " " << p->y() << std::endl;



}

wysota
1st April 2013, 21:54
If you are trying to generate a click for the desktop or window that is outside your application then it won't work. Qt's events are not translated into system events. Using postEvent()/sendEvent() you can only inject events for your own application.

kuppan-j
2nd April 2013, 07:23
canu pls provide me the suggestion to solve the problem

i am seek of this

wysota
2nd April 2013, 09:29
Use native system API. This is out of scope of this forum.