Giving input to a GUI application through another program

旧巷老猫 提交于 2019-12-12 02:35:58

问题


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.


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/12365088/giving-input-to-a-gui-application-through-another-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!