如何使用 pyautogui 一次按下 2 个键?

问题描述 投票:0回答:2

我想在我的 Mac 上按 control + 向左箭头来滑动我的屏幕。

这是我试过的:

import pyautogui

pyautogui.press(["ctrl" ,"left"])

没用。

python pyautogui
2个回答
0
投票

代码似乎是正确的。问题可能是因为您正在 IDE 中运行代码,并且您可能单击了文本或类似的东西(以前发生在我身上)。尝试添加一个 for 循环。

import pyautogui

for i in range(5):
    pyautogui.press(["ctrl" ,"left"])

如果可行,则考虑使用按钮进行简单提示。

import pyautogui

while True:
    result = pyautogui.confirm('click "swipe" to swipe', buttons = ["swipe", "no"])
    if result == "swipe":
        pyautogui.press(["ctrl" ,"left"])

0
投票

为此,您可以使用 pyautogui.hotkey()。在您的示例中,您将运行:

pyautogui.hotkey('ctrl', 'left')
© www.soinside.com 2019 - 2024. All rights reserved.