在 pyautogui 中一起按下按键以使它们发挥作用?

pressing keys together in pyautogui to make them make a function?

我最近一直在尝试创建一个在 python(pyautogui) 中创建新文件夹的程序。 这是我的代码:

import pyautogui;# import the library
pyautogui.press('ctrl');# makes our program to press 'ctrl'
pyautogui.press('n');# makes our program to press 'n'

显然它所做的是分别按下 ctrln,我希望将它们一起按下。请帮忙。

根据 docs:

The press() function is really just a wrapper for the keyDown() and keyUp() functions, which simulate pressing a key down and then releasing it up.

由于要组合多个按键,需要分别调用keyDown()keyUp()

pyautogui.keyDown('ctrl')
pyautogui.press('n')
pyautogui.keyUp('ctrl')