Send some keys to inactive window with python

后端 未结 2 893
星月不相逢
星月不相逢 2020-11-27 07:11

I\'m tryin to send some keys to inactive window/process/programm (win32/64) using python. Already read about pywinauto and SendKeys, but both of them activate window before

2条回答
  •  心在旅途
    2020-11-27 07:45

    The beautiful code by mmsvsbg / Lithian Coth above is fantastic. I confirm it worked on my Windows 10 (64 bit) on Intel i7. Compiling the win32gui (which is now called pywin32) into 64 bit and few other little things too a bit of time but was do-able. For people needing to know step by step instructions to run the code by mmsvsbg/Lithian, I have it detailed out here: https://forums.whirlpool.net.au/thread/3nkwl0k9?p=-1#bottom

    A quicker alternative is you can use a library already written to do the same and maybe more: It's called pywinauto: https://pywinauto.github.io/

    Pywinauto pywinauto is a GUI automation library written in pure Python and well developed for Windows GUI. At its simplest it allows you to send mouse and keyboard actions to dialogs and controls on both Windows and Linux, while more complex text-based actions are supported on Windows only so far (Linux AT-SPI support is under development).

    pywinauto 0.6.0 (Oct, 31) and 0.6.1 (Feb, 08) This big release introduces MS UI Automation (UIA) support (WinForms, WPF, Qt, browsers, Store apps and more). Documentation is built continuously now on ReadTheDocs. See also our improved Getting Started Guide Modules keyboard and mouse can be used out of any window context now. And they work on Linux as well! Multi-backend architecture allows to add new platforms support. Just implement two classes and register your backend! Code style is much closer to PEP8: ClickInput -> click_input. Though backend='win32' is ~80% backward compatible with pywinauto 0.5.4. Initial implementation of the win32_hooks module. Keyboard events (a.k.a hotkeys) and mouse actions handlers can be registered in the system. Example: hook_and_listen.py.

提交回复
热议问题