简体   繁体   English

C++中模拟鼠标键盘输入

[英]Simulate mouse and keyboard input in C++

I am looking for a way to simulate mouse and keyboard input in C++. I am looking for a cross-platform library that will help me achieve this.我正在寻找一种在 C++ 中模拟鼠标和键盘输入的方法。我正在寻找一个可以帮助我实现这一目标的跨平台库。 Any suggestions?有什么建议么?

Target platforms are desktop platforms... Linux, Mac, and Windows only.目标平台是桌面平台... Linux、Mac 和 Windows。

No, input device simulation is extremely platform specific, and finicky even on a single platform.不,输入设备模拟是非常特定于平台的,即使在单一平台上也很挑剔。 It is not a robust technique for any purpose, so you will not find good libraries to implement it.它不是用于任何目的的可靠技术,因此您不会找到好的库来实现它。

The part which is most difficult, once you have the fundamental APIs, is making the devices look realistic to the OS.一旦您拥有了基本的 API,最困难的部分就是让设备看起来对操作系统来说是真实的。 You want gradual mouse movement updates to be sent at a moderately high frequency, like a mouse would do, and reasonable delays between clicks and keypresses.您希望以适度的高频率发送渐进的鼠标移动更新,就像鼠标所做的那样,并在点击和按键之间有合理的延迟。 Executing a timeline of events and doing the basic geometry would probably be assisted by a game library like SDL.执行事件的时间线和做基本的几何可能会得到像 SDL 这样的游戏库的帮助。

If you ignore timing, the OS may decimate mouse motion, debounce buttons, rearrange the order of motion and clicks, ignore keypresses while the trackpad is in use, etc. I wrote just such a tool almost 10 years ago.如果忽略计时,操作系统可能会减少鼠标运动、消除按钮抖动、重新排列运动和点击的顺序、在使用触控板时忽略按键等。大约 10 年前我就写了这样一个工具。

I started such a Library, maybe you want cast a glance.我开了这样一个图书馆,也许你想看一眼。 https://github.com/pythoneer/XInputSimulator https://github.com/pythoner/XInputSimulator

Its in an early state and as the time of writing a bit buggy.它在早期的 state 中,并且在编写时有点错误。 But i hope its getting better:)但我希望它会变得更好:)

Although the input libraries are platform specific, so are the GUI but there are abstract libraries available for such as wxWdigets and Qt which hides the complexity and for input I found this one to be quite interesting尽管输入库是特定于平台的,GUI 也是如此,但是有一些抽象库可用于 wxWdigets 和 Qt,这隐藏了复杂性,对于输入我发现这个非常有趣

https://github.com/jkuhlmann/gainput https://github.com/jkuhlmann/gainput

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM