本文整理汇总了Python中listener.Listener.del_key_sniffer方法的典型用法代码示例。如果您正苦于以下问题:Python Listener.del_key_sniffer方法的具体用法?Python Listener.del_key_sniffer怎么用?Python Listener.del_key_sniffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类listener.Listener
的用法示例。
在下文中一共展示了Listener.del_key_sniffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KMLoger
# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import del_key_sniffer [as 别名]
class KMLoger(threading.Thread):
""" Classe principal """
def __init__(self):
threading.Thread.__init__(self)
self.devices = get_devices()
self.keyfile = ".keymap" # Arquivo padrão para o mapa de caracteres
self.keymap = KeyMap(self.devices)
self.listener = Listener(self.devices)
self.history = History()
self.lock = False
self.listen()
self.copy = False
def record(self):
if self.copy:
self.copy = False
print("\rComandos gravados" + " "*80)
self.listener.del_key_sniffer("rec")
# self.listener.del_mouse_sniffer("mouse")
else:
self.copy = True
print("\rIniciando gravação" + " "*80)
self.history.reset()
self.listener.add_key_sniffer("rec", [self.keymap.get_key_by_func("rec")], self.history.append_event)
# self.listener.add_mouse_sniffer("mouse", self.history.append_event)
def pprint(self, *args):
if not self.copy:
print(args)
def listen(self):
""" Inicializando todas as fun """
self.listener.add_listener("redefine", ecodes.EV_KEY, self.keymap.get_key_by_func("redefine"), self.change_keys)
self.listener.add_listener("quit", ecodes.EV_KEY, self.keymap.get_key_by_func("quit"), self.exit)
self.listener.add_listener("copy", ecodes.EV_KEY, self.keymap.get_key_by_func("rec"), self.record)
self.listener.add_listener("run", ecodes.EV_KEY, self.keymap.get_key_by_func("run"), self.play)
# self.listener.add_listener("save", ecodes.EV_KEY, self.keymap.get_key_by_func("save"), self.history.save)
# self.listener.add_listener("load", ecodes.EV_KEY, self.keymap.get_key_by_func("load"), self.history.load)
# self.listener.add_listener("pause", ecodes.EV_KEY, self.keymap.get_key_by_func("pause"), self.history.sleep)
# self.listener.add_listener("stop", ecodes.EV_KEY, self.keymap.get_key_by_func("stop"), self.history.stop)
# self.listener.add_listener("run_forever", ecodes.EV_KEY, self.keymap.get_key_by_func("run_forever"), self.play_forever)
# self.listener.add_key_sniffer("rec", [self.keymap.get_key_by_func("rec")], self.history.append_event)
# self.listener.add_listener("copy", ecodes.EV_KEY, self.keymap.get_key_by_func("rec"), pprint, "record")
self.listener.add_listener("save", ecodes.EV_KEY, self.keymap.get_key_by_func("save"), self.pprint, "save")
self.listener.add_listener("load", ecodes.EV_KEY, self.keymap.get_key_by_func("load"), self.pprint, "load")
self.listener.add_listener("pause", ecodes.EV_KEY, self.keymap.get_key_by_func("pause"), self.pprint, "sleep")
self.listener.add_listener("stop", ecodes.EV_KEY, self.keymap.get_key_by_func("stop"), self.pprint, "stop")
# self.listener.add_listener("run", ecodes.EV_KEY, self.keymap.get_key_by_func("run"), self.pprint, "play")
self.listener.add_listener("run_forever", ecodes.EV_KEY, self.keymap.get_key_by_func("run_forever"), self.pprint, "play_forever")
def play(self):
if not self.copy:
print("\rplay" + " "*80)
self.history.set_n(1)
self.history.play()
def play_forever(self):
if not self.copy:
self.history.set_n(0)
self.history.play()
def run(self):
self.history.start()
self.listener.run()
self.history.join()
def save_key_map(self):
""" Salva o mapa de caracteres no arquivo padrão. """
pickle.dump( self.keymap, open(self.keyfile, 'wb'), -1)
def exit(self):
if not self.copy:
self.history.exit()
self.listener.exit()
flush_input()
print("\nBye!")
def load_key_map(self):
""" Carrega o mapa de caracteres do arquivo padrão. """
try:
self.keymap = pickle.load(open(self.keyfile, 'rb'))
except IOError:
self.save_key_map()
self.listen()
def change_keys(self):
if not self.copy:
self.keymap.setup()
print("\rNovo mapa de teclas salvo.")
self.save_key_map()
print("\rPrograma precisa ser reiniciado")
self.exit()
def print_keys(self):
self.keymap.print_keymap()