-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support recv method on hook #2
Support recv method on hook #2
Conversation
Any update ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change but it would benefit from some changes to make it more coherent with the rest of the code.
@@ -62,6 +62,34 @@ impl Hook { | |||
pub fn try_recv(&self) -> Result<InputEvent, std::sync::mpsc::TryRecvError> { | |||
InnerHook::try_recv() | |||
} | |||
|
|||
/// Hook::recv() should be an option besides Hook::try_recv() when you want park the current thread until there is an event to process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reword description so that this doc does sound like statement and does not duplicate try_recv() example.
Maybe
This is blocking alternative to Hook::try_recv(). That is it will block the current thread until there is an event from the low-level hook(s) running in the background thread(s), and then will return it.
@@ -14,6 +14,13 @@ mod keyboard_hook_tests { | |||
use willhook::event::IsSystemKeyPress::*; | |||
use mki::Keyboard; | |||
|
|||
#[test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please expand the test before merging.
Test like this would suffice:
imitate key press
imitate other key press
imitate mouse button
imitate mouse move
recv() accordingly to drain all events
call try_recv() to validate the events queue is empty
Dedicated file "blocking.rs" would be good.
/// } | ||
/// # } | ||
/// ``` | ||
pub fn recv(&self) -> Result<InputEvent, std::sync::mpsc::RecvError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should mention this new method in lib.rs doc.
feel free to change it, or close it, we have changed impl to windows-rs |
Support hook recv method to avoid circular loops, sleeps, thread yielding and cpu miss cycles when try_recv is used