[英]How do I simulate a single click on Windows and Linux using C?
What libraries should I use?我应该使用哪些库?
What documentation am I supposed to read?我应该阅读哪些文档?
Maybe someone could drop a code example?也许有人可以放弃一个代码示例?
On Windows, if you want to simulate a mouse click inside a specific window, the relevant window messages are the following (link to documentation included):在 Windows 上,如果您想在特定 window 内模拟鼠标点击,相关的 window 消息如下(包括文档链接):
WM_LBUTTONDBLCLK (on second click, this message is sent instead of WM_LBUTTONDOWN) WM_LBUTTONDBLCLK (第二次点击时,发送此消息而不是 WM_LBUTTONDOWN)
To simulate a mouse click, you can send a window any of these window messages, using the PostMessage() function.要模拟鼠标点击,您可以使用PostMessage() function 发送 window 任何这些 window 消息。
For this function, you require a window handle (HWND) for the target window.对于此 function,您需要目标 window 的 window 句柄 (HWND)。 This can be obtained for example using the EnumWindows() or FindWindow() function.
这可以例如使用EnumWindows()或FindWindow() function 来获得。
However, if you want to simulate a mouse click on the screen instead of inside a specific window, then you will have to use the SendInput() function.但是,如果您想在屏幕上而不是在特定的 window 内模拟鼠标单击,则必须使用SendInput() function。 For further details, see this Stack Overflow question .
有关更多详细信息,请参阅此 Stack Overflow 问题。
Also, be aware that since Windows Vista, for security reasons, it is not possible anymore to send processes with administrative privileges messages from non-privileged processes.另外,请注意,自 Windows Vista 以来,出于安全原因,无法再从非特权进程发送具有管理特权消息的进程。
The above information only applies to Windows.以上信息仅适用于 Windows。 Unfortunately, I can't help you with Linux, but you may find the solution in this Stack Overflow question .
不幸的是,我无法帮助您解决 Linux,但您可以在Stack Overflow question中找到解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.