我在 Mac 上用 Python 进行自动化时遇到困难,在 Windows 上只需使用
pyautogui.press("win") pyautogui.write("edge") pyautogui.press("enter")
但是在Mac上,它是两个键的组合来调出搜索栏,我不知道该怎么做,我已经尝试过使用
pyautogui.hotkey("command", "spaceBar") pyautogui.write("safari") pyautogui.press("return")
我尝试了多种方法(空格键、空格等),但它只在 vs code 中输入 safari。
打开搜索栏并输入“safari”
使用
hold
对我有用。另外“spaceBar”不是有效的键。请改用“空格”。请参阅https://pyautogui.readthedocs.io/en/latest/keyboard.html#keyboard-keys
import pyautogui
with pyaytogui.hold("command"):
pyautogui.press("space")
pyautogui.write("safari")
pyautogui.press("return")