def on_key_pressevent s=streventname prints # printfeventnamekeyboardon_presson_key_presskeyboardwaitesc # 程序会持续运行直到按下esc键keyboardunhook_all # 释放所有的键盘钩子dictionary = 1 02 q 10 a 1e ; 27 z 5a
def on_key_press(event): s=str(event.name) print(s) value = get_value(s) print(value)
def get_value(s): dictionary = {'1': '02', 'q': '10', 'a': '1e', ';': '27', 'z': '5a', 'enter': '0e'} if s in dictionary: return dictionary[s] else: return None
keyboard.on_press(on_key_press) keyboard.wait('esc') keyboard.unhook_all()
原文地址: http://www.cveoy.top/t/topic/iSLc 著作权归作者所有。请勿转载和采集!