Python pyautogui 按功能箭头在功能区中不起作用

Python pyautogui press-function arrows does not work in ribbon

我在 Python 中有一个程序可以启动另一个可执行文件。这个打开的可执行文件的功能区需要做一些自动化操作,所以我使用pyautogui来做。

首先,功能区需要处于“活动”状态,因此我单击了最左侧的部分。 然后我需要使用箭头来更改功能区菜单选择(向左两次)。 然后我需要按回车键打开正确的菜单。 (从 'File' 到 'Scripting')

我为此使用的代码是:

import pyautogui

pyautogui.click(x=0, y=30)
pyautogui.press(['left', 'left']) #this part does not work here
pyautogui.hotkey('enter')

不知何故,点击和输入确实有效,但箭头键无效。我可以使用物理箭头键来更改菜单选择,但此代码不会以某种方式执行这些操作。

有人知道这里出了什么问题以及如何解决吗?

此致, 象头神

编辑:

我尝试用管理员权限打开程序和脚本,但还是不行。不知何故,'enter' 和其他一切正常,除了箭头。

Ganesh,它可能无法与 pyautogui 一起使用,因为您正在使用的程序/界面可能根本没有注册密钥。要使用箭头键或其他特殊键,如 'enter' 我建议使用 pydirectinput

首先,如果尚未安装库

pip install pydirectinput

然后你可以将你的代码重写为

import pyautogui
import pydirectinput

pyautogui.click(x=0, y=30)
pydirectinput.press(['left', 'left']) #this is the updated line of code
pyautogui.hotkey('enter')