CGEventTap

Struct CGEventTap 

Source
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>

Source

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>

Source

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.

Source

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.

Source

pub fn mach_port(&self) -> &CFMachPort

Source

pub fn enable(&self)

Trait Implementations§

Source§

impl Drop for CGEventTap<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.