简体   繁体   English

如何使用 C 模拟 Windows 和 Linux 的单击?

[英]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_LBUTTONDOWN WM_LBUTTONDOWN

WM_LBUTTONUP WM_LBUTTONUP

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.

相关问题 C:我如何模拟8086寄存器? - C: How do I simulate 8086 registers? 如何使用适用于Linux的g ++编译C ++程序以在Windows操作系统中工作? - how do i compile a C++program to work in the windows operating system using g++ for linux? 我们如何用Xlib / C模拟鼠标点击? - How do we simulate a mouse click with Xlib / C? 如何使用gtk3在Linux上的C中的Windows之间切换 - How do I switch between windows in c on linux with gtk3 在 linux 中使用 C 和 uinput 库模拟击键 - Using C to simulate a keystroke in linux with the uinput library 如何使用C在Linux中播放音调? - How do I play a tone in Linux using C? 如何为 Linux 上编写的 Windows 制作 C 可执行文件,但它不会在它运行完成后立即关闭 ZDFFF0A7FA1A55C84C1AZ29 - How do I make a C executable for Windows written on Linux not close the cmd as soon as it finishes running? 如何编写可在Linux和Windows中轻松编译的C ++程序? - How do I write a C++ program that will easily compile in Linux and Windows? 如何在Windows上交叉编译C代码,以便在Unix(Solaris / HPUX / Linux)上运行二进制文件? - How do I cross-compile C code on Windows for a binary to also be run on Unix (Solaris/HPUX/Linux)? 我如何在Windows上设置C环境(也许也兼容Linux) - How do I setup a C environment on Windows (and maybe Linux compatible, too)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM