Zuzu-Typ / winput

winput Python extention - capture and send keyboard and mouse input on Windows
zlib License
28 stars 2 forks source link

Suppress events selectively #3

Closed IGalat closed 2 years ago

IGalat commented 2 years ago

Hi @Zuzu-Typ , I wonder if winput can do this, or maybe it can be added relatively easily: In hook functions for mouse and keyboard return bool, and if false, the event would not propagate further, and will be suppressed for the rest of the system.

I'm basing this on pynput's ability to do so on windows via suppress=True globally, and via win32_event_filter as a callback like I described.

I like winput better for simplicity and responsiveness, but without this ability I can't use it properly.

Zuzu-Typ commented 2 years ago

Hi there @IGalat,

you're in luck, I had a little bit of free time and this issue seemed quite interesting, so I went ahead and composed a solution for it. I'm not 100% sure if this works all of the time, because I only did a little bit of testing, but it seems to work. You can now simply return winput.WP_DONT_PASS_INPUT_ON from a callback function to suppress further processing of the input. Beware though, this means NO application can process that input. Including the Windows Explorer - so you might end up locking up your computer unintentionally. Please see https://github.com/Zuzu-Typ/winput#return-values-for-callback-functions for more detail.

Cheers --Zuzu_Typ--

IGalat commented 2 years ago

Sweet, it works! Thanks a lot :)