我正在尝试创建一个脚本,该脚本可以在按下按键时将所有窗口最小化,除了一个使用pynput键盘侦听器和pygetwindow来控制窗口的脚本。当我尝试运行脚本并按我的键时,我会从侦听器中得到一长串错误。在错误列表的顶部,它说
侦听器回调中未处理的异常
我不明白。这是我的代码:
import pygetwindow as gw
from pynput.keyboard import Listener, KeyCode
from pynput import keyboard
focusKey = KeyCode(char='e')
school = gw.getWindowsWithTitle('Chrome')[0]
def on_press(key):
if key == focusKey:
print('hello world')
school.activate()
# for x in range(6):
# nonSchool = gw.getAllWindows()[x]
# nonSchool.minimize()
elif key == keyboard.Key.esc:
listener.stop()
with Listener(on_press=on_press) as listener:
listener.join()