moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

I'm having an issue running keyboard.GlobalHotKeys and keyboard.Listener at the same time #490

Closed StephenArg closed 2 years ago

StephenArg commented 2 years ago

Running both of these Listeners and a mouse Listener at the same time is causing threading issues. Running just the GlobalHotKeys listener and the mouse Listener at the same time works well though. Is it possible to add a specific hotkey that will be triggered by any key? One that would functionally act like the Listener(on_press=) handler.

moses-palmer commented 2 years ago

Thank you for your report.

If you look at the GlobalHotKeys implementation, you'll notice that it isa very thin wrapper around a listener and a set of hotkey/callback pairs.

My suggestion is that you either create a similar wrapper, or subclass GlobalHotKeys and override _on_press and _on_release.

StephenArg commented 2 years ago

@moses-palmer Thanks for the quick feedback. I'm not sure what I would name this separate wrapper/class when it's functionally the same as GlobalHotKeys with one additional option.

Would it be ok if I passed an optional options dictionary to GlobalHotKeysduring its initialization, maybe one shaped like this for now {every_press: every_press_func}, and then I run that function if it exists within GlobalHotKeys _on_press.

This would function similarly, without adding any new hotkeys like '<*>'. Would you approve an implementation like this?