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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.