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

Support recv method on hook #2

Closed

Conversation

jonatansalemes
Copy link

Support hook recv method to avoid circular loops, sleeps, thread yielding and cpu miss cycles when try_recv is used

@jonatansalemes
Copy link
Author

Any update ?

Copy link
Owner

@myood myood left a 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.
Copy link
Owner

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]
Copy link
Owner

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> {
Copy link
Owner

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.

@myood myood closed this Nov 25, 2023
@myood myood reopened this Nov 25, 2023
@jonatansalemes
Copy link
Author

feel free to change it, or close it, we have changed impl to windows-rs

@myood myood closed this Dec 1, 2023
@myood myood mentioned this pull request Dec 1, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants