我正在尝试使用pyautogui和pynput在Python中编写热键。我试过运行代码,但遇到Typeerror:在似乎是执行行的地方,Nonetype是不可迭代的。我看过其他有类似问题的问题,但是这些解决方案不能解决我的问题。我想念什么?谢谢你的帮助。
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()