【问题标题】:Qt on mac OSX, clicking the desktopMac OSX上的Qt,点击桌面
【发布时间】:2015-08-04 00:09:15
【问题描述】:

我正在 Mac OSX 10 上试验 Qt。 我正在尝试做的事情: 将光标移动到特定位置并左键单击桌面项目(本例中为桌面左上角的“Apple”符号。 我已经使用 QT 测试事件进行了尝试:

首先是向 QTestEventList 添加“mouseClick”并对其进行模拟:

list.addMouseClick(Qt::LeftButton, Qt::NoModifier, point);
QWidget* widget = QApplication::desktop();
list.simulate(widget);

这没有成功。我也试过了:

QPoint point(26,11);
QCursor::setPos(point);
list.addMouseClick(Qt::LeftButton, Qt::NoModifier);
QWidget* widget = QApplication::desktop();
list.simulate(widget);

这也不起作用。我的最后一次尝试:

list.addMousePress(Qt::LeftButton, Qt::NoModifier);
list.addDelay(1000);
list.addMouseRelease(Qt::LeftButton, Qt::NoModifier);
QWidget* widget = QApplication::desktop();
list.simulate(widget);

-> 也没有成功。

是否有可能在应用程序的 DesktopWidget 上使用的 QTestEventList 在 Mac 上完全没有影响?或者我做错了什么......

非常感谢您的帮助 ;-) 提前致谢!

卢克

【问题讨论】:

    标签: c++ macos qt


    【解决方案1】:

    我从未尝试使用 QTestEventList 在 Mac 上模拟鼠标事件。相反,我使用了Mac Quartz Event Services API

    以下代码说明了如何将鼠标移动到某个位置以及如何模拟点击事件:

    #include <ApplicationServices/ApplicationServices.h>
    
    // Move the mouse to the position x, y on the screen
    int x = 26;
    int y = 11;
    CGEventRef mouseEv = CGEventCreateMouseEvent(
                        NULL, kCGEventMouseMoved,
                        CGPointMake(x, y),
                        kCGMouseButtonLeft);
    CGEventPost(kCGHIDEventTap, mouseEv);
    CFRelease(mouseEv);
    
    // Simulate a left mouse click down
    CGEventRef mouseEv = CGEventCreateMouseEvent(
                    NULL, kCGEventLeftMouseDown,
                    getCursorPosition(),
                    kCGMouseButtonLeft);
    CGEventPost(kCGHIDEventTap, mouseEv);
    CFRelease(mouseEv);
    
    // Simulate a left mouse click up
    CGEventRef mouseEv = CGEventCreateMouseEvent(
                    NULL, kCGEventLeftMouseUp,
                    getCursorPosition(),
                    kCGMouseButtonLeft);
    CGEventPost(kCGHIDEventTap, mouseEv);
    CFRelease(mouseEv);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 2012-12-11
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多