Qt 在 mac OSX 上,单击桌面
Qt on mac OSX, clicking the desktop
我正在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);
->也没有成功。
是否有可能在应用程序中的桌面小部件上使用的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);
相关文章:
- QTreeView幻灯片多选后无法使用单击选择
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- QML TableView 使用 QtQuick.Controls 2 单击行
- ImGui 在单击按钮后冻结
- 有没有办法区分Qt小部件是通过鼠标单击还是通过按表键获得焦点?
- 我想使用此代码单击某个特定窗口,但它无法正常工作
- 如何在QSplashScreen中禁用鼠标单击
- 单击一个按钮后创建一个按钮
- C++鼠标单击时的屏幕截图不起作用
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 标签检测鼠标单击 c++
- 如何将我的程序添加到文件和文件夹的macOS右键单击菜单?
- 使用 SFML 在矩形的矢量中查找鼠标单击量
- 在单击 QPushButton 时调用带有参数的函数
- 如何在单击按钮FLTK的确切时刻获得小部件的值
- 如何使用鼠标单击选择多个 QLabel 对象?
- 应用程序最小化时单击显示桌面/最小化全部
- 在窗口或桌面窗口中单击文件
- 将项目插入桌面右键单击菜单从外壳扩展
- Qt 在 mac OSX 上,单击桌面