Giving input to a GUI application through another

2019-09-18 09:49发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-09-18 10:18

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)

查看更多
何必那么认真
3楼-- · 2019-09-18 10:24

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.

查看更多
登录 后发表回答