Unsolved Click and hold LMB
-
Hello,
is there any way in QT to simulate a click and hold of left mouse button? I am looking for easiest solution.
Thanks
rktech -
Hi,
In what context ?
-
@SGaist This is the only thing, that I need to do, click, hold for 5 seconds and release. So the context doesn't matter.
-
Yes it is. Do you need to do that for testing purpose ? Is it for automation ? Are you doing targeting your own application ? Another one ?
-
@SGaist It is for bot for game.
-
@rktech
So you try to do that to OTHER application correct ?so while you can do that internal in Qt app like
QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QCoreApplication::sendEvent(pWidget, mEvnPress); QTimer::singleShot( 5000, [pWidget, mEvnRelease]() { QCoreApplication::sendEvent(pWidget, mEvnRelease); });
It wont work for outside.
You must use native OS calls to do that.
Is this on windows only ?
or you need to work on linux / macos too ? -
@mrjj It is for game, and yes, I have win only.
-
-
@fcarney need to use it in qt c++;
-
@rktech said in Click and hold LMB:
need to use it in qt c++;
Then search for a framework for app automation in C++. I don't think Qt is designed for that.
-
Hi
You have to use native API
https://stackoverflow.com/questions/7492529/how-to-simulate-a-mouse-movementI would check first with autoit3
https://www.autoitscript.com/site/
if it cant click on your game, you wont be able too either. -
I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
What should your 5s-click trigger? What do you want to achieve?EDIT:
Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)
-
@Pl45m4 said in Click and hold LMB:
I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
What should your 5s-click trigger? What do you want to achieve?EDIT:
Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)
Of course it's not my own game.
-
@rktech Where does the requirement that it must be C++ and Qt come from?
-
@mrjj said in Click and hold LMB:
@rktech
So you try to do that to OTHER application correct ?so while you can do that internal in Qt app like
QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QCoreApplication::sendEvent(pWidget, mEvnPress); QTimer::singleShot( 5000, [pWidget, mEvnRelease]() { QCoreApplication::sendEvent(pWidget, mEvnRelease); });
It wont work for outside.
You must use native OS calls to do that.
Is this on windows only ?
or you need to work on linux / macos too ?use of undeclared identifier 'pWidget'
-
@fcarney It is not a requirement, but I want some high-level language.
-
@rktech said in Click and hold LMB:
It is not a requirement, but I want some high-level language.
I have used that python library I pointed to you. I have automated games at home and applications at work with that library. It has functions to find the process, interface to widgets if available, it also has raw clicks based upon position. It already has all the function calls figured out for the windows platform. It is also extremely easy to use compared to a C++ solution. You most likely will not find a widget set in a game. Since they are rendering to opengl or directx. So raw clicks is your best bet.
If you pursue a C++ solution you will have to either find an automation library or dig through the windows api to find the calls to do click events or key events.
You could create a python based qt application and use that automation library for the backend portion of the app.
-
@fcarney The problem is, that I don't know Python.
-
@rktech said in Click and hold LMB:
@fcarney The problem is, that I don't know Python.
It's maybe a good time to learn :-)
-
@SGaist said in Click and hold LMB:
It's maybe a good time to learn :-)
I don't like the syntax, that's the problem.