Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Send mouse click to OS's window manager
I need to simulate a mouse click, and it needs to reach the windows on my desktop, not part of my QT application. I have tried posting a mouseEvent to QApplication::desktop(), but to no avail. Posts on the net suggest that the only way to do this is to write OS-specific code. Comments/suggestions? Thank you.
That's correct. There's no reason for an application to be able to send arbitrarily clicks or other events to other random applications.
Thank you for confirming what I had gleaned from the net. I can assure you, though, that I have good reasons for what I wish to accomplish :-) .
Kent-Dorfman last edited by
you are controlling the gui at the xlib library level, not Qt. Yes, it is possible, but that discussion is way outside the scope of this forum, and there are examples online. Did you google "manual insertion of X11 events"?
@Kent-Dorfman I did find a code sample that works for me on linux: [https://www.linuxquestions.org/questions/programming-9/simulating-a-mouse-click-594576/](link url) . On Windows, the corresponding functionality is with SendInput, with which I am having trouble. But, as you have pointed out, I will raise this at a different forum. Thank you for your time.
JonB last edited by
Under Windows I would say
SendInputis indeed the way to go. "with which I am having trouble": be aware of https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput:
This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level.