我正在尝试重新映射结合 pynput 和 pyautogui 的快捷方式,但出现错误
在使用keyboard.pressed(Key.shift)执行时:AttributeError:模块'pynput.keyboard'没有属性'pressed'
from pynput import keyboard
import pyautogui
# The key combination to check
COMBINATIONS = [
{keyboard.Key.ctrl, keyboard.KeyCode(char='z')},
{keyboard.Key.ctrl, keyboard.KeyCode(char='x')}
]
# The currently active modifiers
current = set()
def execute():
pyautogui.typewrite('Hello world!\n', interval=secs_between_keys)
#pyautogui.hotkey('cmd', 'v')
def on_press(key):
if any([key in COMBO for COMBO in COMBINATIONS]):
current.add(key)
if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
execute()
def on_release(key):
if any([key in COMBO for COMBO in COMBINATIONS]):
current.remove(key)
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
我是一个初学者,不知道为什么我不能在这里使用 pyautogui 函数。你能开导我吗?非常感谢!