#winapi #windows-event #api-bindings #api #windows

win_event_hook

A safe rust API for using SetWinEventHook, powered by the windows crate

6 releases (3 breaking)

0.4.0 Sep 4, 2024
0.3.0 Sep 28, 2023
0.2.0 Jul 5, 2023
0.1.2 Jul 4, 2023

#52 in Windows APIs

Download history 121/week @ 2024-09-01 5/week @ 2024-09-08 15/week @ 2024-09-15 16/week @ 2024-09-22 23/week @ 2024-09-29 2/week @ 2024-10-06

255 downloads per month

MIT license

72KB
988 lines

win_event_hook

Crates.io Documentation MIT licensed Build Status

A safe Rust API for using SetWinEventHook, powered by the windows crate.

Usage

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.

LICENSE

This project is licensed under the MIT license.

Dependencies

~2–38MB
~573K SLoC