def main(): for tune in tuningtable.keys(): print("Temperament ({1:d}) {0:s}".format( tune, list(tuningtable).index(tune))) a = Tuner(tuning=list(tuningtable.keys())[int( input("Temperament [no]?: "))], a1=float(input("A4 pitch frequency [Hz]?: "))) h = keyboard.GlobalHotKeys({ '<ctrl>+x': a.on_activate_x, '<ctrl>+y': a.on_activate_y, '<ctrl>+j': a.on_activate_j, '<ctrl>+k': a.on_activate_k, '<ctrl>+m': a.on_activate_m, '<ctrl>+n': a.on_activate_n, '<ctrl>+v': a.on_activate_v, '<esc>': a.on_activate_esc }) h.start() a.animate() plt.close('all') return 0
def HotkeyChecker(transfer_binds: list, paste_binds: list): s = Sclip() HotkeyDict = {'<ctrl>+<alt>+s': lambda: print("Restored")} failed = False def OnTransfer(): print('Transfered') s.SendtoSecondaryClipboard() def OnPaste(): print('Pasted') s.PasteFromSclip() def Restore(): print("Restored") win.show() for i in transfer_binds: if (i in paste_binds): failed = True break HotkeyDict[HotkeyParser(i)] = OnTransfer for i in paste_binds: if (i in transfer_binds): failed = True break HotkeyDict[HotkeyParser(i)] = OnPaste print(HotkeyDict) if (not failed): with keyboard.GlobalHotKeys(HotkeyDict) as h: h.join() else: return False
def __init__(self): fantome = str(Path.home()) + "/fantome" self.fichiers = get_all_files_list(fantome, [".json"]) print("Liste des fichiers à répéter") for fichier in self.fichiers: print(" ", fichier) self.kb_ctrl = keyboard.Controller() # #print(dir(self.kb_ctrl)) self.mouse_ctrl = mouse.Controller() self.loop = 1 self.backspace = 0 self.all_data = [] for fichier in self.fichiers: with open(fichier) as fd: data = fd.read() fd.close() data = json.loads(data) self.all_data.append(data) print("Longueur des datas =", len(data)) url = "labomedia.org" webbrowser.open(url, new=1, autoraise=True) self.start = 0 print("\n\n Ctrl + Alt + Q pour commencer à répéter ...") with keyboard.GlobalHotKeys({'<ctrl>+<alt>+q': self.on_activate_q})\ as hot: hot.join() print("je ne passe jamais par là")
def __QtAppTick__(delta_seconds): # NOTE 不添加事件处理 Qt 的窗口运行正常 | 添加反而会让 imgui 失去焦点 # QtWidgets.QApplication.processEvents() # NOTE 处理 deleteDeferred 事件 QtWidgets.QApplication.sendPostedEvents() # NOTE 获取时间,判断是否是卡顿状态 global last_tick last_tick = time.time() # NOTE 键盘监听 global listener, key_map, hotkey if not hotkey: return if delta_queue.empty(): delta_queue.put(delta_seconds) elif listener is None: # NOTE 重新构建 键盘 监听 listener = keyboard.GlobalHotKeys(key_map) elif listener not in listener_list: del listener_list[:] listener_list.append(listener) if not listener.is_alive(): listener.start()
def trigger(): if SYSTEM == "Darwin": def for_canonical(f): log.info("for_canonical") return lambda k: f(l.canonical(k)) # hotkey = keyboard.HotKey( # keyboard.HotKey.parse('<cmd>+u'), # on_activate) #Mac无法两个快捷键同时运行 with keyboard.GlobalHotKeys({ '<cmd>+u': on_activate, '<cmd>+0': open_vim, '<cmd>+j': open_tiny_latex }) as hotkey: hotkey.join() l = keyboard.Listener( on_press=for_canonical(hotkey.press), on_release=for_canonical(hotkey.release), # suppress=True ) l.start() elif SYSTEM == "Windows": keyboard.add_hotkey( 'ctrl+u', on_activate, ) # suppress=True) keyboard.add_hotkey('ctrl+alt+i', open_vim) keyboard.add_hotkey('ctrl+j', open_tiny_latex)
def listener_keyboard(self): with keyboard.GlobalHotKeys({ "<shift>+c": self.copy, "<shift>+a": self.about, "<shift>+q": self.quit, }) as h: h.join()
def monitoring_keyboard(): """ monitoring keyboard :return: """ with keyboard.GlobalHotKeys({'<ctrl>': on_activate_h}) as h: h.join()
def listen2(): print("listen") def on_activate_screenshot(): print('<ctrl>+<alt>+h pressed') record.stdin.write('q'.encode("GBK")) record.communicate() # jamtools.screensh() def on_activate_ocr(): print('<ctrl>+<alt>+i pressed') # jamtools.BaiduOCR() def on_activate_screenrecord(): print('alt+c') # recorder.recordchange() def on_activate_actionrun(): print('z+x') # if jamtools.can_controll: # jamtools.controller.running_change() def on_activate_actionrecord(): print('x+c') # if jamtools.can_controll: # jamtools.controller.listening_change() with keyboard.GlobalHotKeys({ '<alt>+z': on_activate_screenshot, '<alt>+x': on_activate_ocr, '<alt>+c': on_activate_screenrecord, 'z+x': on_activate_actionrun, 'c+x': on_activate_actionrecord }) as h: h.join()
def __init__(self, parent, config): super().__init__(parent) self.config = config self.parent = parent # should we be taking screenshots and analyze them (enables with reroll button, # disables with stop_watch_hotkey) self.watching = False self.sct = mss.mss() # limit tries to upload self.timeout = 1 self.tries = 0 def on_reroll(): print("rerolling") self.reroll_pressed = True self.watching = True self.loop() def on_stop_watch(): self.watching = False self.save() self.upload(self.seed.strip()) self.listener = keyboard.GlobalHotKeys({ self.config["hotkeys"]["reroll"]: on_reroll, self.config["hotkeys"]["start-map"]: on_stop_watch, }) self.listener.start()
def run_hotkey_listener(block=False): listener = keyboard.GlobalHotKeys({ '<media_volume_up>': on_volume_up, }) listener.start() print("Hotkey listener started...") if block: listener.join()
def replase_word(): with keyboard.GlobalHotKeys({ '<ctrl>+[': translating, '<ctrl>+]': choose_translating, '<ctrl>+e': exit_from_prog }) as h: h.join()
def keyDetect(): with keyboard.GlobalHotKeys({ '<esc>': escape, '<alt>+d': invertCase, '<alt>+s': doEval, '<alt>+c': altC }) as h: h.join()
def main(): if len(sys.argv) != 2: print("usage:", sys.argv[0], '"COMMAND"') sys.exit() global command command = sys.argv[1] with keyboard.GlobalHotKeys({'<ctrl>+s': on_activate, '<esc>': exit}) as h: h.join()
def start(self): with keyboard.GlobalHotKeys({ '<ctrl>+<shift>+c': self.gui.emit_copy_event, '<ctrl>+<shift>+x': self.gui.emit_copy_event, '<ctrl>+c': self.gui.emit_copy_event, '<ctrl>+x': self.gui.emit_copy_event, '<ctrl>+q': self.gui.quit }) as h: h.join()
def startListeninig(self) -> None: self.listener = keyboard.GlobalHotKeys({ '<alt>+q': self.windowActionsCaller.hideWindow, '<alt>+`': self._appBringerHotkeyPressed }) self.listener.start() print("listening...")
def listen() -> None: with kb.GlobalHotKeys({ settings.capture_hotkey: lambda: kb.Listener.stop(listener), # Stop listener settings.exit_hotkey: lambda: os._exit(0) # Kill program }) as listener: listener.join() return
def run(self): print("Worker running") with keyboard.GlobalHotKeys({ '<shift>': self.show_add, '<ctrl>': self.show_main, '<cmd>+<shift>+g': self.show_options, '<esc>': self.escape }) as h: h.join()
def hot(): print('热键检测开始') with keyboard.GlobalHotKeys({ '=': kaishi, '-': jieshu, 'q': cf, 'r': hd, '2': qianjie }) as h: h.join()
def set_snippets_listener(): global disparador, snippets_filename, snippets_list snippets_list = load_snippets_file(snippets_filename) key_listener = keyboard.Listener(on_press=on_press) key_listener.start() with keyboard.GlobalHotKeys({disparador: on_disparador}) as h: h.join()
def run(self): print("Listener") listener = None if sys.platform.startswith('win'): listener = keyboard.GlobalHotKeys({ '<ctrl>+b': self.handler_activate_wordlist, }) listener.start() listener.join()
def run(self): self.notify.send('start') g = keyboard.GlobalHotKeys({shortcut_enable: self.on_enable, shortcut_disable: self.on_disable}) l = keyboard.Listener(on_press=self.on_press, on_release=self.on_release) g.start() l.start() g.join() l.join()
def _bind_key_to_sound(key: int, object: tkinter.Tk) -> None: logging.debug(f"Bind key: {key}") if KEY_RANGE == "inside_app": hotkey = INSIDE_APP_KEY_MAPPING.get(key + 1, "0") object.bind(hotkey, lambda event: _play_binded_sound(key)) if KEY_RANGE == "system_wide": hotkey = SYSTEM_WIDE_KEY_MAPPING.get(key + 1, "0") keyboard.GlobalHotKeys({ hotkey: lambda: _play_binded_sound(key) }).start()
def save_hotkey(): model_hotkey = str(ent4.get()).replace("^","<ctrl>+").replace("~","<shift>+").replace("!","<alt>+").replace("#","<win>+") print(model_hotkey+' setted as hotkey') with keyboard.GlobalHotKeys({ '%s' %model_hotkey: clip_it, '<alt>+<ctrl>+t': function_1, '<alt>+<ctrl>+y': function_2}) as h: h.join()
def run(self): try: if (self.is_keys_exists): self.global_keylistener_thread = keyboard.GlobalHotKeys( self.mapped_keys) self.global_keylistener_thread.start() print("global listener started") else: print("no keys specified") except: self.emit_error_trigger()
def run(self): def on_activate(): self.paused = not self.paused print('toggle paused to', self.paused) try: with keyboard.GlobalHotKeys({'<ctrl>+<F11>': on_activate}) as h: h.join() except KeyboardInterrupt as e: print("Ctrl+C received, quit") os._exit(1)
def test1(): def on_activate_h(): print('<ctrl>+<alt>+h pressed') def on_activate_i(): print('<ctrl>+<alt>+i pressed') with keyboard.GlobalHotKeys({ '<ctrl>+<alt>+h': on_activate_h, '<ctrl>+<alt>+i': on_activate_i }) as h: h.join()
def main(): gen_prev_month() tray = CustomTray() timer = Timer(tray) tray.run_detached() with keyboard.GlobalHotKeys({ TOGGLE_COMBO: timer.toggle, CHECK_COMBO: timer.check }) as hotkey: hotkey.join()
def start(self, handler: Union[dict, callable]): if callable(handler): self._callback = handler else: self._callback = self._handle_key(handler) print("Keyhooks Starting...") with keyboard.GlobalHotKeys(self._build_hotkeys()) as h: self._listener = h h.join()
def run(self): notify_dict = { key_combo: alert.notify for key_combo, alert in self.alerts_by_hotkey.items() } # Really dumb hack, because windows :( # Make dang sure that whatever dumb terminal you run in doesn't let the interrupt signal be swallowed notify_dict["<ctrl>+c"] = sys.exit with keyboard.GlobalHotKeys(notify_dict) as hotkey_listener: hotkey_listener.join()
def listen_to_hot_keys(block=False): key_map = { '<cmd>+<alt>+<ctrl>+8': hotkey_listener('8'), } if ARGS.volume: key_map['<media_volume_up>'] = hotkey_listener('volume') if ARGS.accent or ARGS.send_midi_record or ARGS.send_midi_play: key_map['`'] = hotkey_listener('accent') listener = keyboard.GlobalHotKeys(key_map) listener.start() print("[Hotkey] Waiting for:", ', '.join(key_map.keys())) if block: listener.join()