pub struct CGEventTap<'tap_life> { /* private fields */ }Expand description
use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop};
use core_graphics::event::{CGEventTap, CGEventTapLocation, CGEventTapPlacement, CGEventTapOptions, CGEventType, CallbackResult};
let current = CFRunLoop::get_current();
CGEventTap::with_enabled(
CGEventTapLocation::HID,
CGEventTapPlacement::HeadInsertEventTap,
CGEventTapOptions::Default,
vec![CGEventType::MouseMoved],
|_proxy, _type, event| {
println!("{:?}", event.location());
CallbackResult::Keep
},
|| CFRunLoop::run_current(),
).expect("Failed to install event tap");Implementations§
Source§impl CGEventTap<'static>
impl CGEventTap<'static>
pub fn new<F: Fn(CGEventTapProxy, CGEventType, &CGEvent) -> CallbackResult + Send + 'static>( tap: CGEventTapLocation, place: CGEventTapPlacement, options: CGEventTapOptions, events_of_interest: Vec<CGEventType>, callback: F, ) -> Result<Self, ()>
Source§impl<'tap_life> CGEventTap<'tap_life>
impl<'tap_life> CGEventTap<'tap_life>
Sourcepub fn with_enabled<R>(
tap: CGEventTapLocation,
place: CGEventTapPlacement,
options: CGEventTapOptions,
events_of_interest: Vec<CGEventType>,
callback: impl Fn(CGEventTapProxy, CGEventType, &CGEvent) -> CallbackResult + 'tap_life,
with_fn: impl FnOnce() -> R,
) -> Result<R, ()>
pub fn with_enabled<R>( tap: CGEventTapLocation, place: CGEventTapPlacement, options: CGEventTapOptions, events_of_interest: Vec<CGEventType>, callback: impl Fn(CGEventTapProxy, CGEventType, &CGEvent) -> CallbackResult + 'tap_life, with_fn: impl FnOnce() -> R, ) -> Result<R, ()>
Configures an event tap with the supplied options and callback, then
calls with_fn.
Note that the current thread run loop must run within with_fn for the
tap to process events. The tap is destroyed when with_fn returns.
Sourcepub unsafe fn new_unchecked(
tap: CGEventTapLocation,
place: CGEventTapPlacement,
options: CGEventTapOptions,
events_of_interest: Vec<CGEventType>,
callback: impl Fn(CGEventTapProxy, CGEventType, &CGEvent) -> CallbackResult + 'tap_life,
) -> Result<Self, ()>
pub unsafe fn new_unchecked( tap: CGEventTapLocation, place: CGEventTapPlacement, options: CGEventTapOptions, events_of_interest: Vec<CGEventType>, callback: impl Fn(CGEventTapProxy, CGEventType, &CGEvent) -> CallbackResult + 'tap_life, ) -> Result<Self, ()>
Caller is responsible for ensuring that this object is dropped before
'tap_life expires. Either state captured by callback must be safe to
send across threads, or the tap must only be installed on the current
thread’s run loop.
pub fn mach_port(&self) -> &CFMachPort
pub fn enable(&self)
Trait Implementations§
Auto Trait Implementations§
impl<'tap_life> Freeze for CGEventTap<'tap_life>
impl<'tap_life> !RefUnwindSafe for CGEventTap<'tap_life>
impl<'tap_life> !Send for CGEventTap<'tap_life>
impl<'tap_life> !Sync for CGEventTap<'tap_life>
impl<'tap_life> Unpin for CGEventTap<'tap_life>
impl<'tap_life> !UnwindSafe for CGEventTap<'tap_life>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more