Sending mouse and keyboard input on Windows


I'm totally at see interacting with the windows API. I've found some references here which I've adapted using the windows crate e.g. with

windows::Win32::UI::WindowsAndMessaging::{GetCursorPos, SetCursorPos};

I'm a bit stuck trying to send mouse down events, and I guess more fundamentally stuck with understanding the mechanics of the windows API.

I've read the following: Using Mouse Input - Win32 apps | Microsoft Docs but it wasn't terribly helpful to me.

Can anyone point me in the right direction of synthesizing mouse and keyboard events on windows in Rust? My ultimate goal is to interact with a time tracking app hosted on a website which takes input via click-dragging a visual representation of a week divided into 30 minute increments.

It may be easier to drive the browser. Have you consider that path?

If I remember correctly mouse_event is used to synthesize ... well ... I suspect you can figure that out. And there's keybd_event. My recollection is that they both work but it's a tedious slog; that both functions are well under-documented. I recall having to work out the various arguments through trial-and-error.

I just noticed SendInput is the replacement.

This function does not reset the keyboard's current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard's state with the GetAsyncKeyState function and correct as necessary.

Ouch. That just brought back a bunch of painful memories.

I hadn't, I'd say I'm equally at sea trying to drive the browser. Do you have any suggestions to make a start down that path?

Check out the fantoccini crate. It's essentially a remote control for your browser, letting you do things like go to a URL, find elements on the page, click on things, fill in forms, etc.