How to send SendKeys to Windows form in python script?

主宰稳场 提交于 2019-12-06 06:23:53

The code can be re-written simpler:

import pywinauto

app = pywinauto.application.Application().connect(title_re='Form1')
Form1 = app.Window_(title_re='Form1', class_name='WindowsForms10.Window.8.app.0.2bf8098_r13_ad1')
Form1.SetFocus()
Form1.TypeKeys("{PAUSE 2}")
Form1.TypeKeys("{TAB 2}{PAUSE 2}{ENTER}")

TypeKeys automatically sets a focus to the Form1 and types the keys. SendKeys doesn't set a focus because it's not aware about the window. That's probably why it doesn't work with SendKeys.

[EDIT] Of course you need to run the script as Administrator.

I got a fixed for this issue. The mistake I was doing is that, I was not running my script as Administrator. So that's why SendKeys event were not happening.

But when I ran my script as Administrator, SendKeys event successfully sent to Windows form.

Thanks Vasily for your help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!