【问题标题】:Pyautogui keyboard commands do not work with Menu bar assignmentsPyautogui 键盘命令不适用于菜单栏分配
【发布时间】:2018-10-30 13:52:41
【问题描述】:

我正在编写一个脚本来自动化 SAP GUI 中的某些管理任务。我可以单击导航、使用选项卡、输入字符串,然后在表单中按 Enter。

问题:当我使用 pyautogui 发送菜单键分配时(例如: pyautogui.press('F12') ),它们似乎不起作用。这迫使我不得不使用其他替代方法(错误的鼠标点击等等)。知道为什么这些不起作用吗?

我可以在没有的情况下工作 - 但我想知道是否有人了解到底发生了什么......如果我能做到,那就太好了!

【问题讨论】:

    标签: python pyautogui


    【解决方案1】:

    pyautogui.press 区分大小写,或者至少在 Windows 上是这样。所以你需要说

    pyautogui.press('f12')
    

    这是list of the keys

    定义这个存根可能很方便

    show_trivial_nags = True #maybe be able to toggle this on the command line
    
    def ci_press(x):
        if x != x.lower() and show_trivial_nags:
            print("WARNING: press commands should be in lower case.")
        pyautogui.press(x.lower())
    

    我使用的测试用例是,在 alt-tab 中使用 Firefox,

    import pyautogui
    pyautogui.hotkey('alt', 'tab')
    # Comment out the first, and the search bar still appears. Comment out the second, and it doesn't.
    pyautogui.press('F3')
    pyautogui.press('f3')
    exit()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 2021-10-01
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      相关资源
      最近更新 更多