pub struct ForwardingController { /* private fields */ }Expand description
Controls the state of an active event forwarding session.
A ForwardingController is returned by EventForwarder::forward_events
and provides thread-safe control over the forwarding thread.
§State
The controller maintains two atomic flags:
pause_flag: Controls whether captured events are currently forwarded.false= forwarding is activetrue= forwarding is paused
exit_flag: Signals that the forwarding session should terminate.false= forwarding session is runningtrue= exit has been requested
§Behavior
Calling Self::pause temporarily disables event forwarding while keeping
the underlying hooks active. Calling Self::resume enables event
forwarding again.
Calling Self::exit permanently signals the forwarding session to stop.
Once exit is requested, the session cannot be resumed.
Dropping the controller also signals the forwarding thread to terminate.
§Example
let controller = forwarder.forward_events()?;
controller.pause();
controller.resume();
if controller.is_forwarding() {
println!("Forwarding is active.");
}
controller.exit()?;Implementations§
Source§impl ForwardingController
impl ForwardingController
Sourcepub fn pause(&self)
pub fn pause(&self)
Pauses event forwarding.
The installed Windows hooks remain active while forwarding is paused,
but captured events are no longer processed by EventForwarder.
Calling this method multiple times has no additional effect.
Sourcepub fn resume(&self)
pub fn resume(&self)
Resumes event forwarding.
Captured events are processed and forwarded to the configured target window again.
Calling this method while forwarding is already active has no additional effect.
Sourcepub fn is_forwarding(&self) -> bool
pub fn is_forwarding(&self) -> bool
Returns whether the forwarding session is currently active.
§Returns
Returns true when forwarding is enabled and false when forwarding
is currently paused.
Sourcepub fn exit(self) -> Result<(), WinErr>
pub fn exit(self) -> Result<(), WinErr>
Stops the event forwarding session and waits for its threads to terminate.
This method signals the forwarding thread to stop processing events and
sends WM_QUIT to the dedicated hook thread. The hook thread then exits
its message loop, removes the installed Windows hooks, and terminates.
The forwarding thread waits for the hook thread to finish before returning.
Once this method has been called successfully, the forwarding session cannot be resumed.
controller.exit()?;