0

I want to send keys to a background program, but the sending doesn't work on all parts of my program (it has no child windows). The following code partially works.

from pywinauto import Application

appWavie = Application(backend='win32').connect(handle=790164)
Wavie = appWavie['Wavie']
Wavie.send_keystrokes('123')

Is it possible to use the code provided by @lucasg in Keyboard event with ctypes as a pywinauto method?

I would like to add PressKey and ReleaseKey methods to pywinauto. My code would look like this:

from pywinauto import Application

appWavie = Application(backend='win32').connect(handle=790164)
Wavie = appWavie['Wavie']

VK_1 = 0x31

Wavie.PressKey(VK_1)
Wavie.ReleaseKey(VK_1)

I want to use these methods because they work in my program where send_keystrokes doesn't work, but PressKey and ReleaseKey don't work in the background.

1 Answers1

0

In pywinauto some of the functionality does not work if the desktop is not active or closed or minimized. because some functions needs active desktop specially for co-ordinate based actions, for example mouse actions,

where you got the decent choice which should do a similar task as your reference answer, Have a look at the send_keys() function. In pywinauto the special keys has deferent notations like for Enter key you should do .send_keys("{ENTER}")

Dev
  • 2,739
  • 2
  • 21
  • 34
  • I already tested `send_keys()`, it didn't work even with the window activated (foreground). I was studying the `pywinauto` module with the aim of adding new methods to the `pywinauto.controls.hwndwrapper.HwndWrapper` class, but I don't know if it's possible or how to do it. Some methods worked as I want, but only in the foreground. I already tried with `pyautogui`, `ahk`, `keyboard`, `win32xxx`. I've had success with `send()`, `send_event()`, `send_input()`, `send_raw()` from `ahk` and `PressKey()`, `ReleaseKey()` from @lucasg, but none of them in the background. – Wavilson Ferreira Jul 12 '22 at 16:04
  • @WavilsonFerreira My guess is that pywin32 works in background. – Dev Sep 13 '22 at 06:36