There isn't a bug in the code since I got it to work.

When I said extra information, I was referring to the fact that you were providing co-ordinate data for the mouse click events (up and down). I assume Windows ignores the data since it doesn't need it. As a result, am I correct in understanding that you don't need to set it?

MOUSEINPUT structure documentation

Apart from this, I'm now interested in simulating keystrokes.

Use FindWindow API to get a handle of the main window
Use FindWindoEx API to get the handle of the button - you would need a program such as Spy++ which can identify all the subwindows within a window
Use SendMEssage to click that button.
This information was very useful, but I'd like to send keys to the application having an active cursor. Could you tell me how to find it?