Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

python - Driving a Windows GUI program from a script

I have to use a Windows simulation package to perform a repetitive task with slightly different options each time.

Since I hate repetitive clicking, on grounds of both laziness and the amount of errors that a human introduces, I would like to drive this program automatically. The program in question doesn't support scripting, there is no API, no COM, nada, nyet, nravin. As far as I can tell, the only way to drive this program automatically is to imitate a human (i.e. keyboard and mouse macros.)

I am aware of AutoHotKey but I don't think it does what I want. (Or it might do what I want, but its scripting language is horrible.)

The requirements are:

  • Must allow time delays between actions, or event detection to trigger actions.

    The simulations can take up to ten minutes to run, so the GUI driver would have to wait until the simulation finishes before starting a new one.

    One way to do this would be to just wait ten minutes and hope that the simulation has finished. An alternative way is to make it event-driven, i.e. watch for the "Simulation running..." dialog to disappear and be replaced by a "Simulation complete" dialog.

  • Must allow composition of complex keyboard input.

    Some of the keyboard input required is different for each simulation run. For example the simulation description might take the format [Project name][Scenario name][Option 1][Option 2]... and this would have to be entered for each simulation.

    I am aware that AutoHotKey allows a basic level of input customisation, but my casual reading of the documentation makes the scripting language look like some kind of eldritch horror.

  • This is for work, so any solution must be free for commercial use.

I will accept any solution that fits the criteria above, but I have a strong preference for something I can drive from Python. However I would also accept automated GUI-testing tools that I could customise to do what I want - possibly a Win32 GUI equivalent of Selenium for browsers? - keyboard macro recorders that will generate custom output, or anything else that works.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sikuli is a visual technology to automate and test graphical user interfaces (GUI) using images (screenshots). Sikuli includes Sikuli Script, a visual scripting API for Jython, and Sikuli IDE, an integrated development environment for writing visual scripts with screenshots easily. Sikuli Script automates anything you see on the screen without internal API's support. You can programmatically control a web page, a Windows/Linux/Mac OS X desktop application, or even an iphone or android application running in a simulator or via VNC.

Look at Sikuli, it worked for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...