Goddard
Goddard

Reputation: 3059

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. Any suggestions?

Target platforms are desktop platforms... Linux, Mac, and Windows only.

Upvotes: 3

Views: 4497

Answers (3)

Aftab Naveed
Aftab Naveed

Reputation: 3869

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

https://github.com/jkuhlmann/gainput

Upvotes: 0

dustin.b
dustin.b

Reputation: 1275

I started such a Library, maybe you want cast a glance. https://github.com/pythoneer/XInputSimulator

Its in an early state and as the time of writing a bit buggy. But i hope its getting better :)

Upvotes: 1

Potatoswatter
Potatoswatter

Reputation: 137780

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. 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.

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.

Upvotes: 3

Related Questions