【问题标题】:Is there a way to hide the action of pyautogui.press()?有没有办法隐藏 pyautogui.press() 的操作?
【发布时间】:2019-08-14 03:00:40
【问题描述】:

我想自动启动 Microsoft Store 应用程序,我想使用 pyautogui 并按以下方式进行操作。

这里gui.press('win')会打开windows搜索弹窗,然后接下来的两行输入skype并分别按Enter

有没有办法可以隐藏gui.press('win') 的操作,这样当我运行脚本时,Skype 会直接启动?

import pyautogui as gui
gui.press("win")
gui.typewrite("Skype")
gui.press("enter")

【问题讨论】:

    标签: python python-2.7 pyautogui


    【解决方案1】:

    既然你想从 python 中自动加载程序,为什么不调用操作系统并运行启动命令呢?

    import os
    
    os.system('start notepad.exe')  # this will start notepad
    
    os.system('start C:\Apps/audacity/audacity.exe') # will start audacity as it is located in the apps folder
    

    至于查找可执行文件,有几个选项可以使用。

    from distutils import spawn
    spawn.find_executable('notepad')
    Out[38]: 'C:\\Windows\\system32\\notepad.exe'
    

    或者

    from shutil import which
    which('notepad')
    Out[55]: 'C:\\Windows\\system32\\notepad.EXE'
    

    【讨论】:

    • @Hojo.Timerwolf,我考虑过使用 os.system,但为此需要应用程序的位置,我无法找到所有内置 Microsoft 应用程序位置的方法,这就是为什么pyautogui 方法。
    • 我刚刚更新了一些查找可执行文件的方法。
    猜你喜欢
    • 2015-12-11
    • 2021-04-28
    • 2019-01-23
    • 2019-02-19
    • 2016-10-04
    • 1970-01-01
    • 2016-01-18
    • 2016-05-29
    • 2021-09-02
    相关资源
    最近更新 更多