Search code examples
pythonpython-3.6pywinauto

How to get rid of delays on double_click_input() actions?


Is there a way I can get rid of delays on double_click_input() actions?

What I'm trying to do is double click the edit box and then type keys here. Maybe both of these actions have some delay, so the whole process performing looks very slow.

Code:

myApp = Desktop(backend='uia').window(title_re='myTitle_re')    
myApp.window(auto_id='myAutoId').window(title='myTitle').double_click_input()
myApp.descendants(title='myTitle', control_type='Edit')[1].type_keys('myKeys')

And an additional question: I tried to use double_click() here, but it always throws an exception:

AttributeError: WindowSpecification class has no 'double_click' method.

Then I tried myApp.window(auto_id='myAutoId').window(title='myTitle').wrapper_object().double_click()

And got:

AttributeError: 'ListItemWrapper' object has no attribute 'double_click'

What should I change to get this work?

I'm using pywinauto 0.6.3.


Solution

  • Answering your first question, you can set some timings to null using global settings. For double_click_input:

    from pywinauto.timings import Timings
    Timings.after_clickinput_wait = 0.0
    Timings.after_setcursorpos_wait = 0.0
    

    For real user input (*_input methods) changing timings may cause modified sequence not to work. But you may experiment for your own risk. Sometimes it's better to use silent methods using window messages like WM_CLICK (for "win32" backend) or UIAutomation Patterns like Invoke Pattern (for "uia" backend).

    double_click is not implemented for "uia" because it's unclear which UIAutomation Pattern should be interpreted as double click action. We have method .invoke() and ButtonWrapper.click = invoke alias. But for non-buttons InvokePattern may have different meaning. That's why we left it as .invoke().

    P.S. Regarding legacy propery text... It can be obtained by .legacy_properties()[u'Value'] for your case (or other value from returned dict). There are methods set_window_text/set_edit_text using ValuePattern so the text can be set silently without any tricks.