coredump
coredump

Reputation: 3107

Giving input to a GUI application through another program

What i want to know is how can you give input to a GUI app that is closed source and does not have any public API.

To be more concise, let's say you open solitaire and want through a program to play it. Or, to go even to the basics, you have an GUI app with a button and you want to click it through another program.

I know the question is a little vague, but that's the best I can phrase it. Please help me with some edits or some comments to make it more specific.

Upvotes: 0

Views: 581

Answers (2)

Matt
Matt

Reputation: 231

Assuming its an X11 app in Linux you could connect the process to one end of a named pipe and then echo X-Input events down the other end of the pipe.

Upvotes: 0

hmjd
hmjd

Reputation: 122001

Investigate SendInput(). It can be used to simulate mouse movements and key presses.

To locate a Windows application using its GUI you can use EnumWindows() to locate a Window with a particular title. This will provide a Window handle. To give that window focus, you could:

  • obtain the window handle via EnumWindows()
  • use GetWindowRect() to get the co-ordinates of the window rectangle
  • move the mouse to within the bounds of the window using SendInput() and simulate a mouse click using SendInput()

I have done this once, and it is infuriatingly difficult to get right. Once you start your program sit on your hands: don't touch the mouse or the keyboard.

(I have no knowledge on how to do anything like this on Linux)

Upvotes: 1

Related Questions