Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse hotkey functionality with pynput #17

Open
daermond opened this issue Apr 26, 2024 · 1 comment
Open

Add mouse hotkey functionality with pynput #17

daermond opened this issue Apr 26, 2024 · 1 comment

Comments

@daermond
Copy link

pyinput give the possibility to add mouse hotkey, like the side buttons. It is much convenient to use it with a thumb click. Could you elaborate it to add mouse hotkey functionality as well with pynput? It can be used next to the keyboard hotkeys.
I have done it personally to test it and works great.
Like:

from pynput import mouse

    def run(self):
        """Run the recorder, setting up hotkeys and entering the main loop."""
        keyboard.add_hotkey(config.RECORD_HOTKEY, self.handle_hotkey_wrapper)
        keyboard.add_hotkey(config.CANCEL_HOTKEY, self.cancel_all)
        keyboard.add_hotkey(config.CLEAR_HISTORY_HOTKEY, self.clear_messages)
        def on_click(x, y, button, pressed):
            if button == getattr(mouse.Button, config.MOUSE_CANCEL_HOTKEY) and pressed:
                self.cancel_all()
            elif button == getattr(mouse.Button, config.MOUSE_RECORD_HOTKEY) and pressed:
                self.handle_hotkey_wrapper()
            elif button == getattr(mouse.Button, config.MOUSE_CLEAR_HISTORY_HOTKEY) and pressed:
                self.clear_messages()
        mouse_listener = mouse.Listener(on_click=on_click)
        mouse_listener.start()
        print(f"Press '{config.RECORD_HOTKEY}' to start recording, press again to stop and transcribe.\nDouble tap to give the AI access to read your clipboard.\nPress '{config.CANCEL_HOTKEY}' to cancel recording.\nPress '{config.CLEAR_HISTORY_HOTKEY}' to clear the chat history.")

Or replace the keyboard as well with pynput as in a pull request suggested.

Config.py:

### HOTKEYS ###
CANCEL_HOTKEY = 'ctrl + alt + x'
CLEAR_HISTORY_HOTKEY = 'ctrl + alt + f12'
RECORD_HOTKEY = 'ctrl + shift + space'
# Mouse keys are:'x1' mouse sidebutton 1, 'x2' for mouse sidebutton 2, 'middle' for mouse middle button
MOUSE_CANCEL_HOTKEY = 'x1'
MOUSE_CLEAR_HISTORY_HOTKEY = 'middle'
MOUSE_RECORD_HOTKEY = 'x2'
@ILikeAI
Copy link
Owner

ILikeAI commented Apr 26, 2024

Oh awesome having it hooked up to a mouse button would be awesome! I'm looking at swapping away from the current keyboard library, at very least I will add support for pynput.
Thanks for submitting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants