本文整理汇总了Python中listener.Listener.run方法的典型用法代码示例。如果您正苦于以下问题:Python Listener.run方法的具体用法?Python Listener.run怎么用?Python Listener.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类listener.Listener
的用法示例。
在下文中一共展示了Listener.run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import run [as 别名]
senders = None
index = -1
self.ON = False
finally:
file.close()
return senders, index
if len(sys.argv) == 5 and sys.argv[1] == '--send':
print 'Starting the measurement tool from', sys.argv[2], 'to', sys.argv[3]
time.sleep(1)
senders, index = parse(sys.argv[4], sys.argv[2])
if index == -1:
sys.exit(0)
sender = Sender(sys.argv[2], sys.argv[3], senders, index)
if sender.isAlive():
sender.run()
sender.close()
elif len(sys.argv) == 3 and sys.argv[1] == '--listen':
print 'Listening at', sys.argv[2]
listener = Listener(sys.argv[2])
if listener.isAlive():
listener.run()
listener.close()
else:
print 'python measurement.py [--send|--listen] addr'
sys.exit(0)
示例2: KMLoger
# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import run [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()