我是
pywinauto
的新手,我想从 Windows 开始菜单打开我自己的应用程序。
为此,如果我知道如何从 Windows 开始菜单打开 Google chrome,那么我就可以处理我的应用程序。 我已经浏览了下面 URL 中提到的代码,但不明白。 使用 pywinauto 自动化启动按钮
这是我尝试过的代码:
import pywinauto.application
app = pywinauto.application.Application().connect(path="explorer")
app.TaskBar.print_control_identifiers()
我知道这不是 pywinauto,但我对 pyautogui 更有经验。 在命令提示符中输入:
pip install pyautogui
代码:
import pyautogui
from time import sleep
x, y = pyautogui.position() # gives the x and y of the bottom right corner
pyautogui.click(x, y-1)
sleep(1) # ensure that we clicked may need to be extended for older systems
# or just pyautogui.write('win')
pyautogui.write("Google Chrome")
sleep(1) #ensure we typed it may need to be extended for older systems
pyautogui.press("enter") #press enter
给你!它会在两秒钟内打开 chrome。 如果您想访问网站,请添加以下内容:
sleep(3) #google chrome takes forever to load. Just checking. Also may
need to be extended for older systems.
pyautogui.moveTo(10, y-10)
sleep(3)
pyautogui.typewrite("URL/domain to go to", 0.25) #the 0.25 is a delay of 1/4 of a second, to bypass new chrome anti-bot protection.
sleep(12) #ensure we typed it. make sure to extend by the rule of 4 characters=add 1 also add 1 to that to make sure. this supports 40 character long URLs
pyautogui.press("enter") #press enter
好的,就这样吧。刚刚制作了一个脚本来打开 chrome 并(可选)转到 URL。