python - Pyautogui 键盘命令不适用于菜单栏分配

标签 python pyautogui

我正在编写一个脚本来自动执行 SAP GUI 中的某些管理任务。我可以单击导航、使用制表符、输入字符串并在表单中按回车键。

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

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

最佳答案

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

pyautogui.press('f12')

这是一个 list of the keys .

定义这个 stub 可能会很方便

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()

关于python - Pyautogui 键盘命令不适用于菜单栏分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50439834/

相关文章:

python - 在 Confluence API 中保留新行

python - 使用对数轴刻度时 Matplotlib Latex 错误,版本相关

Python 在网页上自动打字

Python 屏幕截图

python - setup(name) 和 Extension(name) 之间有什么关系

python - Lisp 在 Python 中的 "some"?

带有滚动条的 Python Turtle 窗口

python - 尝试使用 pip 在 python 中安装新模块时,cmd 正在搜索错误的文件路径

python - 如何运行无限while循环直到找到Python中的值?

Python pyautogui.click 是右键单击而不是左键单击