import pynput keyboard = pynput.keyboard.Controller() mouse = pynput.mouse.Controller() def on_release(key): try: if key == pynput.keyboard.Key.backspace: mouse.press(pynput.mouse.Button.left) mouse.release(pynput.mouse.Button.left) print('按了一下鼠标') keyboard.press('E') keyboard.release('E') print('按了一下E') if key == pynput.keyboard.Key.esc: print('退出') return False except AttributeError: print('special key {0} pressed'.format( key)) def on_press(key): print('按了一下{0}'.format(key)) print('正在启动程序....请稍等几秒.单击英雄之后按backspace替换成野怪.按ESC之后退出') with pynput.keyboard.Listener( on_press=on_press, on_release=on_release) as listener: listener.join()