如何使用pywinauto从Windows开始菜单打开谷歌浏览器



我是pywinauto新手,我想从Windows开始菜单打开我自己的应用程序。

为此,如果我知道如何从窗口开始菜单中打开谷歌浏览器,那么我就可以处理我的应用程序。 我已经浏览了以下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
pyautogui.typewrite("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。

最新更新