Crates.io | win_event_hook |
lib.rs | win_event_hook |
version | 0.4.0 |
source | src |
created_at | 2023-07-04 20:54:09.871708 |
updated_at | 2024-09-04 00:55:02.369162 |
description | A safe rust API for using SetWinEventHook, powered by the windows crate |
homepage | |
repository | https://github.com/bengreenier/win_event_hook |
max_upload_size | |
id | 908331 |
size | 71,829 |
A safe Rust API for using SetWinEventHook
, powered by the windows
crate.
To use win_event_hook
, add the following to your Cargo.toml
:
[dependencies]
win_event_hook = "0.1"
Then create a configuration and install a hook, for example:
use win_event_hook::events::{Event, NamedEvent};
// create our hook config
let config = win_event_hook::Config::builder()
.skip_own_process()
.with_dedicated_thread()
.with_events(vec![
// to see these, try right clicking
Event::Named(NamedEvent::ObjectShow),
Event::Named(NamedEvent::ObjectHide),
// to see this, try moving around the cursor
Event::Named(NamedEvent::ObjectLocationChange),
])
.finish();
// and our handler
let handler = |ev, _, _, _, _, _| {
println!("got event: {:?}", ev);
};
// install the hook
let hook = win_event_hook::WinEventHook::install(config, handler)?;
When hook
is dropped, an uninstall is attempted automatically. Uninstallation may fail - to handle failures, instead call uninstall
yourself, for example:
// building on the above example
// uninstall the hook
hook.uninstall()?;
For more information, see the generated documentation.
This project is licensed under the MIT license.