pub struct GuiProcessWatcher { /* private fields */ }Expand description
Monitors GUI processes, using the Windows shell hook API.
§Examples
use ib_hook::process::{GuiProcessEvent, GuiProcessWatcher};
let watcher = GuiProcessWatcher::new(Box::new(|event| {
println!("Process event: {event:?}");
})).unwrap();
println!("Monitoring GUI processes...");
std::thread::sleep(std::time::Duration::from_secs(60));Implementations§
Source§impl GuiProcessWatcher
impl GuiProcessWatcher
Sourcepub fn new(callback: impl GuiProcessCallback) -> Result<Self>
pub fn new(callback: impl GuiProcessCallback) -> Result<Self>
Creates a new GUI process watcher with the given callback.
The callback will be called for each process event (window creation, activation, rude activation, and replacement).
pub fn with_on_hooked( callback: impl GuiProcessCallback, on_hooked: impl FnOnce() + Send + 'static, ) -> Result<Self>
Sourcepub fn with_dedup(callback: impl GuiProcessCallback) -> Result<Self>
pub fn with_dedup(callback: impl GuiProcessCallback) -> Result<Self>
Creates a new GUI process watcher with a deduplication buffer.
This version deduplicates process events to avoid duplicate notifications when multiple windows are created by the same process.
Sourcepub fn with_filter_dedup<I1, I2>(
callback: I1,
) -> GuiProcessWatcherWithFilterDedupBuilder<I1, I2>
pub fn with_filter_dedup<I1, I2>( callback: I1, ) -> GuiProcessWatcherWithFilterDedupBuilder<I1, I2>
Creates a new GUI process watcher with a deduplication buffer and filters to reduce syscalls.
This version deduplicates process events to avoid duplicate notifications when multiple windows are created by the same process.
Source§impl GuiProcessWatcher
impl GuiProcessWatcher
Sourcepub fn for_each<I1, I2>(f: I1) -> GuiProcessWatcherForEachBuilder<I1, I2>
pub fn for_each<I1, I2>(f: I1) -> GuiProcessWatcherForEachBuilder<I1, I2>
Apply a function on every existing and new GUI process exactly once.
Race condition / TOCTOU is handled in this function, although not perfect.
(Processes created after start_time before hooked will be lost,
but they can still be detected if they create new windows (and activate windows if create_only is false)
in the future, which is likely to happen.)
§Examples
use ib_hook::process::GuiProcessWatcher;
let _watcher = GuiProcessWatcher::for_each(|pid| println!("pid: {pid}"))
.filter_image_path(|path| {
path.and_then(|p| p.file_name())
.is_some_and(|n| n.to_ascii_lowercase() == "notepad.exe")
})
.build();
std::thread::sleep(std::time::Duration::from_secs(60));