def control(*args): global play_state if play_state == 'running': play_state = 'stopping' elif play_state == 'idle': kbd.call_later(play, args=args, delay=1)
def test_call_later(self): triggered = [] def fn(arg1, arg2): assert arg1 == 1 and arg2 == 2 triggered.append(True) keyboard.call_later(fn, (1, 2), 0.01) self.assertFalse(triggered) time.sleep(0.05) self.assertTrue(triggered)
def send_keyboard_event(ctx, command_name, timing=DEFAULT_PRESS_TIME): if command_name in POSSIBLE_TIMED_COMMANDS: keyboard.press(POSSIBLE_TIMED_COMMANDS[command_name]) keyboard.call_later( lambda: keyboard.release(POSSIBLE_TIMED_COMMANDS[command_name]), delay=timing) elif command_name in POSSIBLE_NON_TIMED_COMMANDS: keyboard.send(POSSIBLE_NON_TIMED_COMMANDS[command_name])
def test_call_later(self): self.triggered = False def trigger(): self.triggered = True keyboard.call_later(trigger, delay=0.1) self.assertFalse(self.triggered) time.sleep(0.2) self.assertTrue(self.triggered)
def loop_press(hotkey, time_max, time_current=0, t=None): if time_current < time_max: new_t = time.time() dt = new_t - t time_current += dt keyboard.press_and_release(hotkey=hotkey) keyboard.call_later(fn=loop_press, args=(hotkey, time_max, time_current, new_t), delay=0.2) else: return
def send_message(event): time = grab_image(event) if config["use_mode"] == "no_enter": keyboard.send('enter') keyboard.write(time) keyboard.call_later(lambda: keyboard.send('enter'), (), 0.01) # keyboard.tap(Key.enter) # keyboard.type(time) # sleeper.sleep(0.03) # keyboard.tap(Key.enter) # keyboard.call_later(lambda: keyboard.write(time), (), 0.1) elif config["use_mode"] == "yes_enter": keyboard.write(time)
def pressLetter(strLetter, t): if isShifted(strLetter): # we have to convert all symbols to numbers if strLetter in conversionCases: strLetter = conversionCases[strLetter] keyboard.press('left shift') keyboard.press(strLetter.lower()) keyboard.release('left shift') keyboard.call_later(keyboard.release, args=(strLetter), delay=t) else: keyboard.press(strLetter) keyboard.call_later(keyboard.release, args=(strLetter), delay=t) return
def on_press_action(c): if disabled: if c.scan_code == 1 or c.scan_code == 28: # esc, enter keyboard.call_later(escape_typing, (), delay=0.05) return if c.scan_code >= 2 and c.scan_code <= 13 or c.scan_code == 41 or c.scan_code == 15 or c.scan_code == 44 or c.scan_code == 45: if not keys[0] and keys[1] and not keys[3] or not keys[0] and not keys[1] and keys[3]: keyboard.call_later(update_workspaces, (), delay=0.05) return if c.scan_code == 1 or c.scan_code == 28: # esc, enter keyboard.call_later(escape_typing, (), delay=0.05) return if (c.scan_code == 25 or c.scan_code == 19) and keys[1]: # p keyboard.call_later(block_with_typing, (), delay=0.05) return if c.name not in keymap: return keynum = keymap[c.name] if keys[keynum]: return keys[keynum] = True update_light()
def controls_update(queue, delay, mode): if queue: print('Current queue:') print(queue) if mode == 'anarchy': action = queue.popleft() elif mode == 'democracy': actions = {} for action in queue: actions[action] = 0 for action in queue: actions[action] += 1 max = queue[0] for action, count in actions.items(): if actions[max] > count: max = action queue.clear() print('Current action:') print(action) keyboard.press(action) keyboard.call_later(keyboard.release, args=([action]), delay=delay)
def on_press_action(c): if c.scan_code >= 2 and c.scan_code <= 13 or c.scan_code == 41 or c.scan_code == 15: if not keys[0] and keys[ 1] and not keys[3] or not keys[0] and not keys[1] and keys[3]: keyboard.call_later(update_workspaces, (), delay=0.05) return if c.scan_code == 25 and keys[1]: # p keyboard.call_later(block_with_typing, (), delay=0.05) if c.scan_code == 1 or c.scan_code == 28: # esc, enter keyboard.call_later(escape_typing, (), delay=0.05) if c.name not in keymap: return keynum = keymap[c.name] if keynum != 2 and keynum != 3 and keyboard.is_pressed("shift+alt"): will_switch_lang[0] = False if keys[keynum]: return keys[keynum] = True update_light()
def set_hotkey(self, event): keyboard.call_later(self.set_hotkey2, args=[event], delay=0.001)
def control(self): if self.state == 'running': self.state = 'stopping' elif self.state == 'idle': kbd.call_later(self.play, delay=1)
def control(args_dict): global play_state if play_state: play_state = False else: kbd.call_later(lambda: play(**args_dict), delay=1)