1

So I've had a good look around, and this is the closest I could find to what I need to do: http://bytes.com/topic/python/answers/23100-windows-dialog-box-removal

But it's only part of it.

So I have a script that needs to run fully automated. Currently it's being stopped by a Windows dialog box prompting the user to click 'OK'.

Is it possible to register some sort of handler that when a dialog box opens is fired and selects the 'OK' option for it? Any ideas how to do this/where I can get futher info on it?

NOTE: My goal isn't just to keep the code going, a requirement is to select 'OK' on the dialog box before continuing.

  • 1
    You should rename this question to `Changing windows application dialog box behavior from Python`. – Croll Jul 15 '15 at 11:30

2 Answers2

0

You have to create a thread in the background. Different threads may run at one time. Dialog box stops current thread and waits while user make a choice. This is normal behavior.

Python has very easy threading API. Thread is function that is passed as an argument to a thread class constructor. Thread executes this function then, and you may start several threads, they will not lock the current thread. Move your dialog or background code to a separate thread.

Samples: Simple threading event example More info: https://docs.python.org/3/library/threading.html

Making program automatically select OK in that dialog box is not possible for a Python program. Well, there are several techniques, but they require C++ and other extended skills.

Community
  • 1
  • 1
Croll
  • 3,631
  • 6
  • 30
  • 63
  • You can kill the process using shell just like you create it, from any thread if you need, but you cannot change the behavior of program (do you have source code?). Updated the answer @user3420034 – Croll Jul 15 '15 at 11:29
  • @user3420034 this is the worst you can do with python, stop it. write a C app for this and use it in your python application if so. – Croll Jul 15 '15 at 13:26
  • @user3420034 all you need is to send a windows message to process when dialog window appears, to simulate the click. To know if it happen, i can only recommend hooks. This is about 40 lines in C++, but in python this is not possible (hook). – Croll Jul 15 '15 at 13:43
0

There is a package called Lackey which can scan the screen for a predefined pattern (the image of the Dialog in this case) then type the keyboard ('Enter' in this case).

It is a python implementation of Sikuli. So all supporting docs can be found here.

jps
  • 20,041
  • 15
  • 75
  • 79