Exemplo n.º 1
0
def shortcut_toggle():
    global p
    p ^= True
    if p:
        notifier("Hotkeys Active")
        keyboard.add_hotkey('ctrl+shift+"',
                            lambda: b_bulb.toggle(),
                            suppress=True)
        keyboard.add_hotkey('ctrl+shift+1',
                            lambda: bulb_brigtness(1),
                            suppress=True)
        keyboard.add_hotkey('ctrl+shift+2',
                            lambda: bulb_brigtness(50),
                            suppress=True)
        keyboard.add_hotkey('ctrl+shift+3',
                            lambda: bulb_brigtness(100),
                            suppress=True)
        keyboard.add_hotkey('ctrl+shift+4',
                            lambda: custom_brightness(None),
                            suppress=True)
    else:
        notifier("Hotkeys Passive")
        keyboard.remove_hotkey('ctrl+shift+"')
        keyboard.remove_hotkey('ctrl+shift+1')
        keyboard.remove_hotkey('ctrl+shift+2')
        keyboard.remove_hotkey('ctrl+shift+3')
        keyboard.remove_hotkey('ctrl+shift+4')
Exemplo n.º 2
0
 def test_add_hotkey_single_step_suppress_removed(self):
     keyboard.remove_hotkey(
         keyboard.add_hotkey('ctrl+a', trigger, suppress=True))
     self.do(d_ctrl + d_a, d_ctrl + d_a)
     self.assertEqual(
         keyboard._listener.filtered_modifiers[dummy_keys['left ctrl'][0]
                                               [0]], 0)
Exemplo n.º 3
0
    def disable(self):
        if hasattr(self, 'handlers'):
            import keyboard

            for handler in self.handlers:
                keyboard.remove_hotkey(handler)
            del self.handlers
Exemplo n.º 4
0
    def disable(self):
        if hasattr(self, 'handlers'):
            import keyboard

            for handler in self.handlers:
                keyboard.remove_hotkey(handler)
            del self.handlers
Exemplo n.º 5
0
def record_mouse():
    def save_point(points: list):
        point = pyautogui.position()
        points.append(point)

        logger.info(f"{point=} noktası kaydedildi")

        return points

    def start_mouse_listener(points: list):
        keyboard.remove_hotkey(POINT_HOTKEY)
        keyboard.remove_hotkey(CLOSE_HOTKEY)
        keyboard.add_hotkey(HOTKEY, record_mouse)

        logger.info("Kayıt tamamlandı")

        for point in points:
            pyautogui.moveTo(x=point.x, y=point.y, duration=1)

    keyboard.remove_hotkey(HOTKEY)

    logger.info("Kayıt başlatıldı")
    logger.info(f"{POINT_HOTKEY} ile konumları seçin")
    logger.info(f"{CLOSE_HOTKEY} ile kaydı tamamlayın")

    # Capture mouse points
    points = []
    keyboard.add_hotkey(POINT_HOTKEY, save_point, args=(points, ))
    keyboard.add_hotkey(CLOSE_HOTKEY, start_mouse_listener, args=(points, ))
Exemplo n.º 6
0
    def clear_play_keybind(self):
        """ Clear the Play/Pause keybind """

        if (len(self.playKey) > 0):
            self.playKeyEntry.clear()
            self.playKey = ''
            keyboard.remove_hotkey(self.play)
Exemplo n.º 7
0
def two_wait(hotkey_a=None,
             hotkey_b=None,
             suppress=False,
             trigger_on_release=False):
    """
    Near identical copy of the wait function present in keyboard,
    but can take two hotkeys, allowing for custom global interrupts
    """
    if hotkey_a and hotkey_b:
        lock = _Event()
        # Pylint warns that the lambda may be unnecessary, but testing other cases shows that the program excepts without lambda
        # test cases included `lambda e: lock.set()` `lock.set()` `lock.set`
        # pylint: disable=unnecessary-lambda
        remove_a = keyboard.add_hotkey(hotkey_a,
                                       lambda: lock.set(),
                                       suppress=suppress,
                                       trigger_on_release=trigger_on_release)
        remove_b = keyboard.add_hotkey(hotkey_b,
                                       lambda: lock.set(),
                                       suppress=suppress,
                                       trigger_on_release=trigger_on_release)
        lock.wait_stutter()
        keyboard.remove_hotkey(remove_a)
        keyboard.remove_hotkey(remove_b)
    else:
        while True:
            _time.sleep(1e6)
    def unregister_hotkeys(self, scope='', force=False):
        """Unregister hotkeys."""
        if not scope:
            for scope in self.hooked_keys:
                self.unregister_hotkeys(scope)
            if force:
                try:
                    keyboard.unhook_all()
                except Exception:
                    pass
            self.keyboard_state = dict()
        else:
            while self.hooked_keys[scope]:
                if scope == 'ctrlx':
                    try:
                        keyboard.remove_hotkey(self.hooked_keys[scope].pop())
                    except ValueError:
                        pass
                else:
                    try:
                        keyboard.unhook(self.hooked_keys[scope].pop())
                    except ValueError:
                        pass

            module_logger.info('Unregistered {} hotkeys.'.format(scope))
Exemplo n.º 9
0
 def callback():
     try:
         keyboard.remove_hotkey(self.undo_split_hotkey)
     except AttributeError:
         pass
     self.undo_split_key = keyboard.read_hotkey(False)
     try:
         if self.undo_split_key == self.splitLineEdit.text(
         ) or self.undo_split_key == self.resetLineEdit.text(
         ) or self.undo_split_key == self.skipsplitLineEdit.text(
         ) or self.undo_split_key == self.undosplitLineEdit.text():
             self.undo_split_hotkey = keyboard.add_hotkey(
                 self.old_undo_split_key, self.undoSplit)
             self.afterSettingHotkeySignal.emit()
             return
     except AttributeError:
         self.afterSettingHotkeySignal.emit()
         return
     try:
         if '+' in self.undo_split_key:
             self.undo_split_hotkey = keyboard.add_hotkey(
                 self.old_undo_split_key, self.undoSplit)
             self.afterSettingHotkeySignal.emit()
             return
     except AttributeError:
         self.afterSettingHotkeySignal.emit()
         return
     self.undo_split_hotkey = keyboard.add_hotkey(
         self.undo_split_key, self.undoSplit)
     self.undosplitLineEdit.setText(self.undo_split_key)
     self.old_undo_split_key = self.undo_split_key
     self.afterSettingHotkeySignal.emit()
     return
Exemplo n.º 10
0
 def delete_hotkey(self):
     keyboard.remove_hotkey(self.hotkey_string)
     self.hotkey_label.config(text="")
     self.hotkey_string = ""
     label = self.action["text"][:-1]
     self.app.update_config("HOTKEYS", label, self.hotkey_string, "config.txt")
     self.app.update_dialogue("Hotkey deleted.")
Exemplo n.º 11
0
 def unregister_function(self, key_combo):
     """ Stop tracking function at key_combo """
     keyboard.remove_hotkey(key_combo)
     self.logger.info(
         "Unregistered function at keycombo <%s>",
         key_combo.lower(),
     )
Exemplo n.º 12
0
def main():
    global is_pressed

    parser = argparse.ArgumentParser()
    parser.add_argument("--path", type=str)
    parser.add_argument("--interval", default=0.01, type=float)
    args = parser.parse_args()

    im = misc.imread(args.path, mode="RGB")
    palette = create_palette("picker.png", 50)

    draws = create_draws(im, palette)
    pixel_w, pixel_h, start_w, start_h = get_board_size()

    for k, v in draws.items():
        if len(v) == 0: continue

        print("Select ({}, {}) picker and press s".format(k[0], k[1:]))
        hk = keyboard.add_hotkey("s", draw,
                                 (v, (pixel_w, pixel_h),
                                  (start_w, start_h), args.interval))
        while True:
            if is_pressed:
                keyboard.remove_hotkey(hk)
                is_pressed = False
                break
Exemplo n.º 13
0
 def stop_app():
     global running
     logging.info('App stopped...')
     running = False
     keyboard.remove_hotkey(options['hotkey'])
     keyboard.remove_hotkey('esc')
     sys.exit()
Exemplo n.º 14
0
    def test_suppression(self):
        def dummy():
            pass

        keyboard.add_hotkey('a+b+c', dummy, suppress=True)
        keyboard.add_hotkey('a+g+h', dummy, suppress=True, timeout=0.01)

        for key in ['a', 'b', 'c']:
            assert not self.press(key)
        for key in ['a', 'b', 'c']:
            assert not self.release(key)

        assert self.click('d')

        for key in ['a', 'b']:
            assert not self.press(key)
        for key in ['a', 'b']:
            assert not self.release(key)

        assert self.click('c')

        for key in ['a', 'g']:
            assert not self.press(key)
        for key in ['a', 'g']:
            assert not self.release(key)

        time.sleep(0.03)
        assert self.click('h')

        keyboard.remove_hotkey('a+g+h')
        keyboard.remove_hotkey('a+b+c')

        assert self.click('a')
Exemplo n.º 15
0
    def clear_stop_keybind(self):
        """ Clear the stop keybind """

        if (len(self.stopKey) > 0):
            self.stopKeyEntry.clear()
            self.stopKey = ''
            keyboard.remove_hotkey(self.stop)
Exemplo n.º 16
0
    def _update_reset_hotkey(self, text, selected_hotkey):

        keyboard.remove_hotkey(self.reset_hotkey)
        self.reset_hotkey = selected_hotkey
        keyboard.add_hotkey(self.reset_hotkey, self.resetPushButton.click)
        self.resetPushButton.setToolTip(self.reset_hotkey)
        self.resetAction.setShortcut(self.reset_hotkey)
        self._EXISTING_HOTKEYS.update({text: self.reset_hotkey})
Exemplo n.º 17
0
    def close(self):
        try:
            keyboard.remove_hotkey(self.capture_key)
        except KeyError:
            pass

        self.window.Close()
        self.editor.stop()
Exemplo n.º 18
0
    def callback():
        # try to remove the previously set hotkey if there is one.
        try:
            keyboard.remove_hotkey(self.split_hotkey)
        except AttributeError:
            pass
        #this error was coming up when loading the program and
        #the lineEdit area was empty (no hotkey set), then you
        #set one, reload the setting once back to blank works,
        #but if you click reload settings again, it errors
        #we can just have it pass, but don't want to throw in
        #generic exception here in case another one of these
        #pops up somewhere.
        except KeyError:
            pass

        # wait until user presses the hotkey, then keyboard module reads the input
        self.split_key = keyboard.read_hotkey(False)

        # If the key the user presses is equal to itself or another hotkey already set,
        # this causes issues. so here, it catches that, and will make no changes to the hotkey.
        try:
            if self.split_key == self.splitLineEdit.text() \
                    or self.split_key == self.resetLineEdit.text() \
                    or self.split_key == self.skipsplitLineEdit.text() \
                    or self.split_key == self.undosplitLineEdit.text() \
                    or self.split_key == self.pausehotkeyLineEdit.text():
                self.split_hotkey = keyboard.add_hotkey(
                    self.old_split_key, self.startAutoSplitter)
                self.afterSettingHotkeySignal.emit()
                return
        except AttributeError:
            self.afterSettingHotkeySignal.emit()
            return

        # keyboard module allows you to hit multiple keys for a hotkey. they are joined
        # together by +. If user hits two keys at the same time, make no changes to the
        # hotkey. A try and except is needed if a hotkey hasn't been set yet. I'm not
        # allowing for these multiple-key hotkeys because it can cause crashes, and
        # not many people are going to really use or need this.
        try:
            if '+' in self.split_key:
                self.split_hotkey = keyboard.add_hotkey(
                    self.old_split_key, self.startAutoSplitter)
                self.afterSettingHotkeySignal.emit()
                return
        except AttributeError:
            self.afterSettingHotkeySignal.emit()
            return

        # add the key as the hotkey, set the text into the LineEdit, set it as old_xxx_key,
        # then emite a signal to re-enable some buttons and change some text in GUI.
        self.split_hotkey = keyboard.add_hotkey(self.split_key,
                                                self.startAutoSplitter)
        self.splitLineEdit.setText(self.split_key)
        self.old_split_key = self.split_key
        self.afterSettingHotkeySignal.emit()
        return
Exemplo n.º 19
0
 def remove_hotkey(self, keys):
     keys = keys.toString()
     if 'Print' in keys or '*' in keys:
         lst = self.printKeyShortcuts if 'Print' in keys else self.mulKeyShortcuts
         lst.remove(sum(filter(lambda x: x.lower() in ('alt', 'shift', 'ctrl'),
                               keys.split('+')), lambda x: Modifiers[x.lower()]))
     else:
         keys = '+'.join(map(lambda x: self.qt_to_keyboard.get(x, x), keys.split('+')))
         keyboard.remove_hotkey(keys)
Exemplo n.º 20
0
    def show(self):

        self.makegeo()
        keyboard.remove_hotkey(hotkey)
        keyboard.add_hotkey(hotkey, self.hideandexecute, trigger_on_release=True, suppress=True)

        self.deiconify()
        self.lift()
        print('SHOW is CTRL pressed:' + str(keyboard.is_pressed('ctrl')))
Exemplo n.º 21
0
    def start_mouse_listener(points: list):
        keyboard.remove_hotkey(POINT_HOTKEY)
        keyboard.remove_hotkey(CLOSE_HOTKEY)
        keyboard.add_hotkey(HOTKEY, record_mouse)

        logger.info("Kayıt tamamlandı")

        for point in points:
            pyautogui.moveTo(x=point.x, y=point.y, duration=1)
def doQuit():
    global quitting
    for key in hotkeys:
        try:
            keyboard.remove_hotkey(key)
        except KeyError as _:
            pass
    print('Done.\n')
    quitting = 1
Exemplo n.º 23
0
 def hideandexecute(self):
     global chosen
     print(f"Chosen {chosen}")
     keyboard.remove_hotkey(hotkey)
     keyboard.add_hotkey(hotkey, self.show, suppress=True)
     keyboard.release(hotkey)
     self.hide()
     #self.destroy()
     globals()[hotboxbuttons[chosen]]()
     print('HIDEANDEXECUTE is CTRL pressed:' + str(keyboard.is_pressed('ctrl')))
Exemplo n.º 24
0
 def remove_toggle_key(self):
     """
     Remove the toggle key if it exists
     """
     if self.hotkey != None:
         try:
             keyboard.remove_hotkey(self.hotkey)  # remove previous hotkey
         except:
             pass
         self.hotkey = None
Exemplo n.º 25
0
def toggle_record_new_hotkey():
    global window, recording, hotkey, keyboard_recording, new_hotkey_btn, show_hotkey, toggle_hotkey, is_on
    is_on = False
    # If grumby is in recoring mode
    if recording:
        recording = False
        keyboard_recording = keyboard.stop_recording()
        new_hotkey_btn['text'] = "Change Hotkey"
        change_background("deactivated")
        modifiers = []
        # The keyboard library records all keys pressed while grumby is in recording mode
        # This loop parses for any modifier keys that have been pressed (excluding the windows key)
        # As well as the last char charachter pressed. All other key presses are disguarded.
        print(f"\n\n\nkeyboard recording: {keyboard_recording}\n\n\n")
        for keypress in keyboard_recording:
            print(f"\nkeypress {keypress.name}\n")
            if keypress.name in ('shift', 'ctrl', 'alt'):
                if keypress.name not in (modifiers):
                    modifiers.append(keypress.name)
            if keypress.name not in ('shift', 'ctrl', 'alt', 'windows', 'esc',
                                     'unknown'):
                pressed_key = keypress.name
        if len(modifiers) > 0:
            new_hotkey = "+".join(modifiers) + "+" + pressed_key
        else:
            # If no keypresses were entered while grumby was in recording mode
            try:
                new_hotkey = pressed_key
            except:
                pass
        keyboard_recording = None
        # If the pressed keys were valid then modify the hotkey an ui, else reset to previously set hotkey
        try:
            toggle_hotkey = keyboard.add_hotkey(new_hotkey, toggle_grumby)
            hotkey = new_hotkey
            new_show_hotkey_text = f"Toggle Grumby with '{hotkey}'"
            if len(new_show_hotkey_text) < 30:
                show_hotkey['text'] = new_show_hotkey_text
            else:
                show_hotkey['text'] = f"Toggle Grumby with\n'{hotkey}'"
        except:
            messagebox.showinfo(
                "*Wiggles Mustache*",
                "No keypresses were recorded.\nNo changes were made.\n\nPress multiple keys at the same time. For example: 'ctrl+shift+m' or 'alt+a'"
            )
            toggle_hotkey = keyboard.add_hotkey(hotkey, toggle_grumby)
        save_grumby_state()
    # If grumby is not in recording mode, then change ui and start recording
    else:
        recording = True
        keyboard.remove_hotkey(toggle_hotkey)
        new_hotkey_btn['text'] = "Press To Stop"
        change_background("recording")
        keyboard.start_recording()
Exemplo n.º 26
0
    def change_hotkey(self, hotkey, button):
        if not (self.sound_buttons_data[button][1] is None):
            keyboard.remove_hotkey(self.sound_buttons_data[button][1])

        self.sound_buttons_data[button][1] = hotkey
        print(
            f'Set hotkey {hotkey} to sound {self.sound_buttons_data[button][0]}.'
        )

        keyboard.add_hotkey(
            hotkey, lambda: self.play(self.sound_buttons_data[button][0]))
Exemplo n.º 27
0
    def _update_stort_hotkey(self, text, selected_hotkey):

        keyboard.remove_hotkey(self.stort_hotkey)  # Remove previous hotkey
        self.stort_hotkey = selected_hotkey  # Update self.stort_hotkey
        keyboard.add_hotkey(
            self.stort_hotkey,
            self.stortPushButton.click)  # Register new hotkey in keyboard
        self.stortPushButton.setToolTip(
            self.stort_hotkey)  # Update tooltip for the button
        self.stortAction.setShortcut(self.stort_hotkey)  # Update stort QAction
        self._EXISTING_HOTKEYS.update({text: self.stort_hotkey})
Exemplo n.º 28
0
    def record_hotkey(self):
        rec = keyboard.read_hotkey(suppress=False).upper()
        keyboard.remove_hotkey(self.hotkey_string)
        keyboard.add_hotkey(rec, self.app.save_time)
        self.hotkey_label.config(text=rec)
        self.hotkey_string = rec

        label = self.action["text"][:-1]
        self.app.update_config("HOTKEYS", label, self.hotkey_string, "config.txt")

        self.app.update_dialogue("Hotkey has been set.")
Exemplo n.º 29
0
    def stop_quick_capture(self):
        try:
            keyboard.remove_hotkey(self.capture_key)
        except KeyError:
            pass

        self.enable_coords_input()
        self.window.Element('capture').Update(text="Capture from DCS F10 map")
        self.window.Element('quick_capture').Update(disabled=False)
        self.window.Element('capture_status').Update("Status: Not capturing")
        self.capturing = False
Exemplo n.º 30
0
def go():
    try:
        keyboard.add_hotkey('ctrl + shift + insert', add_to_pac)
        keyboard.add_hotkey('ctrl + shift + delete', del_from_pac)
        while 1:
            pass
    except Exception as e:
        print(e)
        keyboard.remove_hotkey('ctrl + shift + insert')
        keyboard.remove_hotkey('ctrl + shift + delete')
        print_tip(True)
        return go()
Exemplo n.º 31
0
def makeahotkeynowplease():
    Hotkey = modifier.get() + ", " + E1.get()
    try:
        keyboard.remove_hotkey(Hotkey)
    except:
        print("Hotkey [" + Hotkey + "] created for the first time")
    TextToType = E2.get().replace("///", "\n")
    if toggle_mode.get() == 1:
        print("Test")
    else:
        keyboard.add_hotkey(Hotkey, lambda: keyboard.write(TextToType))
        print(toggle_mode)
Exemplo n.º 32
0
 def wait_quit(self, hotkey=None, suppress=False, trigger_on_release=False):
     """
     Blocks the program execution until the given hotkey is pressed. The wait lock can be released via lock.set().
     Warning: lock.set() is an end-condition operation currently, as it will free the global lock variable for all
     cases in code.
     """
     if hotkey:
         remove = keyboard.add_hotkey(hotkey, lambda: self.lock.set(),
                                      suppress=suppress, trigger_on_release=trigger_on_release)
         self.lock.wait()
         keyboard.remove_hotkey(remove)
     else:
         raise ValueError('please supply a hotkey to wait for')
Exemplo n.º 33
0
    def test_remove_hotkey(self):
        keyboard.press("a")
        keyboard.add_hotkey("a", self.fail)
        keyboard.clear_all_hotkeys()
        keyboard.press("a")
        keyboard.add_hotkey("a", self.fail)
        keyboard.clear_all_hotkeys()
        keyboard.press("a")

        keyboard.clear_all_hotkeys()

        keyboard.add_hotkey("a", self.fail)
        with self.assertRaises(ValueError):
            keyboard.remove_hotkey("b")
        keyboard.remove_hotkey("a")
Exemplo n.º 34
0
    def triggers(self, combination, keys):
        self.triggered = False

        def on_triggered():
            self.triggered = True

        keyboard.add_hotkey(combination, on_triggered)
        for group in keys:
            for key in group:
                self.assertFalse(self.triggered)
                self.press(key)
            for key in reversed(group):
                self.release(key)

        keyboard.remove_hotkey(combination)

        self.wait_for_events_queue()

        return self.triggered
 def _clear_hotkeys(self): #pylint: disable=no-self-use
     keyboard.remove_hotkey("ctrl+up")
     keyboard.remove_hotkey("ctrl+down")
Exemplo n.º 36
0
 def test_add_hotkey_single_step_suppress_removed(self):
     keyboard.remove_hotkey(keyboard.add_hotkey('a', trigger, suppress=True))
     self.do(d_a, d_a)
Exemplo n.º 37
0
 def test_add_hotkey_single_step_suppress_removed(self):
     keyboard.remove_hotkey(keyboard.add_hotkey('ctrl+a', trigger, suppress=True))
     self.do(d_ctrl+d_a, d_ctrl+d_a)
     self.assertEqual(keyboard._listener.filtered_modifiers[dummy_keys['left ctrl'][0][0]], 0)