qt 3.0.3中的鼠标单击事件

时间:2013-04-01 16:41:16

标签: qt

鼠标按钮clicki我试图在特定的坐标上创建一个自动鼠标点击事件。

此源代码将鼠标指针移动到坐标区域,但不是单击。

请帮助我解决此问题或建议任何新想法自动执行鼠标点击事件。

注意:我使用的是QT 3.0.3

 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; 
} 

1 个答案:

答案 0 :(得分:0)

QApplication::sendEvent向QApplication发送内部事件,而不是系统范围的事件。您可能需要特定于系统才能发送类似的事件。这是windows的函数调用:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx

但即使有这样的电话,你也只能使用某些窗口,除非你的UIAccess是真的,而你的程序是位于硬盘右侧的签名应用程序。

编辑:这是一个页面,其中包含一些在Linux中发送输入的示例:

http://www.linuxquestions.org/questions/programming-9/simulating-a-mouse-click-594576/

希望有所帮助。

相关问题