通过另一个程序将输入提供给GUI应用程序 [英] Giving input to a GUI application through another program
问题描述
我想知道的是如何为封闭源且没有任何公共API的GUI应用程序提供输入.
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.
为简明起见,假设您打开单人纸牌游戏并希望通过一个程序来玩它.或者,要了解基础知识,您可以使用带有按钮的GUI应用程序,并想通过其他程序单击它.
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.
推荐答案
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:
- 通过
EnumWindows()
获取窗口句柄 - 使用
GetWindowRect()
获取窗口矩形的坐标 - 使用
SendInput()
将鼠标移至窗口范围内,并使用SendInput()
模拟鼠标单击
- 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 usingSendInput()
我曾经做过一次,而且很难做到正确.一旦启动程序,坐上手:请勿触摸鼠标或键盘.
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.
(我不知道如何在Linux上做类似的事情)
这篇关于通过另一个程序将输入提供给GUI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!