[英]Windows c++ simulate click admin
I have a program in Qt5 Windows 10 where I simulate clicks (to help a friend with a disability with a special device). 我在Qt5 Windows 10中有一个模拟点击的程序(以帮助有特殊功能的残障朋友)。 I use SendInput.
我使用SendInput。 The problem is that when I simulate a click to press a key on the Windows Virutal Keyboard (osk.exe), it does not work.
问题是,当我模拟单击以按下Windows Virutal键盘(osk.exe)上的某个键时,它不起作用。 In fact, it works but only if I run the program as administrator.
实际上,它可以工作,但前提是我必须以管理员身份运行该程序。 However, I would like it to work even when the program is not run as admin.
但是,即使程序未以管理员身份运行,我也希望它能正常工作。
Any suggestions ? 有什么建议么 ?
Qt has everything you need in order to simulate input, so you don't need to use SendInput
Qt具有模拟输入所需要的一切,因此您无需使用
SendInput
First, create a QMouseEvent
and then call QCoreApplication::postEvent
首先,创建一个
QMouseEvent
,然后调用QCoreApplication::postEvent
The implementation would depend on what exactly you want to simulate, but your code would look something like this: 实现将取决于您要模拟的内容,但是您的代码将如下所示:
// Pos is the position of the click
QMouseEvent *me = new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(reciever, me); // Where reciever is a QObject handling the event
EDIT : Another snippet worth trying: 编辑 :另一个值得尝试的代码段:
#include <windows.h>
QApplication::desktop()->cursor().setPos(globalX,globalY);
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 1, 1, 0, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.