我正在尝试使用 pyautogui 和 pynput 在 Python 中编写热键。我试过运行代码,但我得到一个 Typeerror: Nonetype is not iterable at what似乎是执行行。我已经查看了其他类似问题的问题,但这些解决方案并不能解决我的问题。我错过了什么?谢谢你的帮助。
from pynput import keyboard
from pynput.keyboard import Controller, Listener
import pyautogui
from pyautogui import *
# The key combination to check
COMBINATIONS = [
pyautogui.hotkey('Cttl', 'shift', 'z')
]
# The currently active modifiers
current = set()
def execute():
keyboard.KeyCode(char='K'), pyautogui('Ctrl', 's')
print ("K pressed")
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 Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()