3

I am trying to perform the zoom in/out command with pywinauto.

I have two solutions in mind. The first one is emulating the CTRL + wheel command. I must say the window seems to zoom in, but the wheel_dist parameter does not effect the amount of zoom.

import pywinauto
import random

app = pywinauto.application.Application(backend='uia').connect(title_re='BlueStacks')
win = app.top_window()
win.set_focus()
    
win_rect = win.rectangle()
coords = (random.randint(win_rect.left, win_rect.right), random.randint(win_rect.top, win_rect.bottom))

pywinauto.keyboard.send_keys('{VK_CONTROL down}')
pywinauto.mouse.scroll(coords=coords, wheel_dist=100)
pywinauto.keyboard.send_keys('{VK_CONTROL up}')

The second solution is emulate the CTRL + + command. The solution does not work.

pywinauto.keyboard.send_keys('{VK_CONTROL down}{+ 20}{VK_CONTROL down}')

I have read the documentation and I don't find anything wrong with my code. I suppose this operation is not fully supported, but I am here to listen and learn.

Any thoughts?

Samuele Colombo
  • 685
  • 2
  • 6
  • 20

1 Answers1

1

This code works:

pywinauto.keyboard.send_keys("{VK_CONTROL down}")
for i in range(9):
    pywinauto.keyboard.send_keys("{+ down}")
    time.sleep(0.01)
    pywinauto.keyboard.send_keys("{+ up}")
    time.sleep(0.01)
pywinauto.keyboard.send_keys("{VK_CONTROL up}")

But nothing is wrong with your code. You should add an issue in: https://github.com/pywinauto/pywinauto/issues

David Pratmarty
  • 596
  • 1
  • 4
  • 19
  • You're right, my code is not technically wrong, but I guess the real issue was the delay between key up and down. It was too short in my case! – Samuele Colombo Nov 13 '20 at 14:35