ILikeAI / AlwaysReddy

AlwaysReddy is a LLM voice assistant that is always just a hotkey away.
MIT License
524 stars 50 forks source link

Add config option to suppress native hotkey functionality (Windows only) #42

Closed Jobus0 closed 1 month ago

Jobus0 commented 1 month ago

For people who want to use other hotkeys that have conflicting native functionality. Enabled by default because I think it's safe to assume that most users don't want their AlwaysReddy hotkeys to simultaneously trigger other stuff.

Only added support for Windows since pynput does not seem to support key suppression.

Jobus0 commented 1 month ago

Hold on.

The soundfx thread waiting added at https://github.com/ILikeAI/AlwaysReddy/commit/c5ff6855ed22a84ab64f47c1516eafcae0c416d6#diff-e85051bd66472be829acf9f76e7fed60f659f9fb13fdeff0d0077ac5413f9569R47 is interfering with the suppression of the hotkeys. Is that .join() needed for Linux specifically? I'm on Windows, and bypassing that .join() solves all the issues, and makes the hotkeys more responsive too.

if platform.system() != "Windows":
    sound_thread.join()  # Wait for the thread to complete
ILikeAI commented 1 month ago

The soundfx thread waiting added at c5ff685#diff-e85051bd66472be829acf9f76e7fed60f659f9fb13fdeff0d0077ac5413f9569R47 is interfering with the suppression of the hotkeys. Is that .join() needed for Linux specifically? I'm on Windows, and bypassing that .join() solves all the issues, and makes the hotkeys more responsive too.

Hmmm i cant remember exactly why that is there to be honest. Im a little confused though, your first commits about dealing with cases where the always reddy conflicts with a system hotkey right? I cant see how waiting for the audio thread to finish relates to that?

Jobus0 commented 1 month ago

Im a little confused though, your first commits about dealing with cases where the always reddy conflicts with a system hotkey right? I cant see how waiting for the audio thread to finish relates to that?

Since the keyboard listener is running on the main thread, any long thread sleeping makes the suppression fail. Just putting time.sleep(0.3) (300 ms) at the top of main.cancel_all() makes the suppression of the cancel hotkey fail. Shorter sleeps (<250 ms) is fine though, so stuff like waiting for a file to delete is no problem.

I don't really understand the technicality of why it behaves like this, but if we just avoid waiting for sounds to finish playing, it should be a non-issue.

ILikeAI commented 1 month ago

Ahh okay awesome that makes sense. i just tested it without the join on ubuntu and it works fine so i removed it all together! Nice catch, ill merge it now.

Also what version of windows are you on? win 10 or 11?

Jobus0 commented 1 month ago

Alright, nice!

I'm on Windows 11.

ILikeAI commented 1 month ago

Okay awesome! I had heard a couple of reports from windows 11 users that they were having issues. For you does it detect they hotkeys even when the terminal isnt in focus? For example can you be in the browser and still press the record hotkey?

Thanks for the contribution by the way! Much appreciated!

Jobus0 commented 1 month ago

I had heard a couple of reports from windows 11 users that they were having issues. For you does it detect they hotkeys even when the terminal isnt in focus? For example can you be in the browser and still press the record hotkey?

There's a common issue with global hotkey apps on Windows where the hotkeys don't work when a process that has been run with admin privileges is focused, unless the global hotkey app was run with admin privileges as well. Some programs and games run with admin privileges by default.

If I run my browser as admin, AlwaysReddy's hotkeys stop working as long as the browser window is in focus. As soon as I restart AlwaysReddy with admin privileges too, it works fine again.

So for those users, I would suggest running run_AlwaysReddy.bat with "Run as administrator" from the context menu.

Alternatively, make a shortcut to run_AlwaysReddy.bat, then go context menu > Properties > Shortcut > Advanced and check "Run as administrator". Then it will always run as admin when using that shortcut.

ILikeAI commented 1 month ago

Dude this is super useful! I didnt know this but it makes a lot of sense. Thanks for sharing!