Skip to content
Advertisement

Pywinauto timings waiting 0.5 seconds instead of immediate

I have the following Pywinauto code and timings waiting is 0.5 seconds instead of immediate. How to get itimmediately?

  • To click a button and go to the next message:
JavaScript

When I run, the interval between clicks is 0.5 seconds:

JavaScript

However, when I move my mouse frantically, it goes faster:

JavaScript

What exactly am I doing wrong?

Edit: For a more generic approach and testing, tweaked code, same results

JavaScript

Advertisement

Answer

You need to pre-search the element app2 and save it as wrapper object:

JavaScript

In your current code app2 = app.TBPanel2 is a WindowSpecification object which is just a criteria to search. So when you’re calling .rectangle() or .click_input() the search procedure is called implicitly every time. This is described in the Getting Started Guide, Chapter “Window Specification”.

Also I’d recommend to name the variable tb_panel2_spec or tb_panel2_wrapper instead of app2 to avoid confusion about its type.

P.S. Also the reliable cross-platform way to measure time in Python is import timeit; timeit.default_timer().

PS2: from pywinauto import mouse is not necessary because you’re using method .click_input().


EDIT3:

The real problem is win32gui.GetDoubleClickTime() which returns 500 ms. Method .click_input() tries to eliminate double click this way. We can add optional parameter to disable this wait. You can workaround it by monkey patching win32gui. Add this code at the beginning:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement