gpt4 book ai didi

c++ - Qt on mac OSX,点击桌面

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:11 25 4
gpt4 key购买 nike

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

首先是将“mouseClick”添加到 QTestEventList 并模拟它:

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 上根本没有效果?或者我做错了什么......

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

吕克

最佳答案

我从未尝试过使用 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);

关于c++ - Qt on mac OSX,点击桌面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27598993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com