### Get Device Filter (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Retrieves the filter configuration for a specified device. Filters determine which input events are allowed or blocked. Handles both mouse and keyboard devices. ```rust pub fn get_filter(&self, device: Device) -> Filter { if is_invalid(device) { return Filter::KeyFilter(KeyFilter::empty()); } let raw_filter = unsafe { raw::interception_get_filter(self.ctx, device) }; if is_mouse(device) { let filter = match MouseFilter::from_bits(raw_filter) { Some(filter) => filter, None => MouseFilter::empty(), }; Filter::MouseFilter(filter) } else { let filter = match KeyFilter::from_bits(raw_filter) { Some(filter) => filter, None => KeyFilter::empty(), }; Filter::KeyFilter(filter) } } ``` -------------------------------- ### Get Device Precedence (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Retrieves the precedence level for a given device. Precedence determines the order in which input events are processed. ```rust pub fn get_precedence(&self, device: Device) -> Precedence { unsafe { raw::interception_get_precedence(self.ctx, device) } } ``` -------------------------------- ### Get Hardware ID using Interception (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Retrieves the hardware identifier for a given device using the Interception library. It handles buffer conversion and unsafe calls to the underlying C function. ```rust pub fn get_hardware_id(&self, device: Device, buffer: &mut [u8]) -> u32 { let ptr = buffer.as_mut_ptr(); let len = match u32::try_from(buffer.len()) { Ok(l) => l, Err(_) => u32::MAX, }; unsafe { raw::interception_get_hardware_id(self.ctx, device, std::mem::transmute(ptr), len) } } ``` -------------------------------- ### Rust: MouseFlags methods for accessing flag values Source: https://docs.rs/interception/0.1.2/interception/struct Offers methods to access the underlying bit representation and check the state of MouseFlags. These include getting the raw bits and checking if the set is empty or contains all flags. ```rust pub const fn bits(&self) -> u16 Returns the raw value of the flags currently stored. ``` ```rust pub const fn is_empty(&self) -> bool Returns `true` if no flags are currently stored. ``` ```rust pub const fn is_all(&self) -> bool Returns `true` if all flags are currently set. ``` -------------------------------- ### Get TypeId of a value in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Implements the `Any` trait for generic types, providing a `type_id` method. This method returns the `TypeId` of the underlying data, useful for runtime type checks. ```rust fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Interception API Overview Source: https://docs.rs/interception/0.1.2/src/interception/lib Provides methods for creating an interception context, managing device precedence and filters, and waiting for input events. ```APIDOC ## Interception Management ### Description Provides methods for creating an interception context, managing device precedence and filters, and waiting for input events. ### Methods - **`new()`**: Creates a new Interception context. Returns `Some(Interception)` on success, `None` on failure. - **`get_precedence(device: Device)`**: Retrieves the precedence level for a given device. - **`set_precedence(device: Device, precedence: Precedence)`**: Sets the precedence level for a given device. - **`get_filter(device: Device)`**: Retrieves the filter settings for a given device. Returns `Filter::MouseFilter` or `Filter::KeyFilter`. - **`set_filter(predicate: Predicate, filter: Filter)`**: Sets a filter for devices based on a predicate and a filter configuration. - **`wait()`**: Waits indefinitely for an input event from any device. Returns the `Device` that generated the event. - **`wait_with_timeout(duration: Duration)`**: Waits for a specified duration for an input event. Returns the `Device` that generated the event, or a special value if the timeout occurs. ``` -------------------------------- ### Create Interception Context (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Creates a new interception context. Returns `None` if the context creation fails. This is the primary entry point for using the interception library. ```rust pub fn new() -> Option { let ctx = unsafe { raw::interception_create_context() }; if ctx == std::ptr::null_mut() { return None; } Some(Interception { ctx: ctx }) } ``` -------------------------------- ### Rust: Generic clone_to_uninit Method (Nightly) Source: https://docs.rs/interception/0.1.2/interception/struct Details the `clone_to_uninit` method for generic types `T` that implement `Clone`. This is a nightly-only experimental API for copy-assignment to uninitialized memory. ```rust impl CloneToUninit for T where T: Clone, { unsafe fn clone_to_uninit(&self, dest: *mut u8) } ``` -------------------------------- ### Sending and Receiving Strokes Source: https://docs.rs/interception/0.1.2/src/interception/lib Handles sending and receiving input strokes (mouse or keyboard) for specified devices. ```APIDOC ## Stroke Manipulation ### Description Handles sending and receiving input strokes (mouse or keyboard) for specified devices. ### Methods - **`send(device: Device, strokes: &[Stroke])`**: Sends a slice of `Stroke` objects to the specified device. Returns the number of strokes sent. - **`receive(device: Device, strokes: &mut [Stroke])`**: Receives input strokes from the specified device into the provided mutable slice. Returns the number of strokes read. ``` -------------------------------- ### Rust Blanket Implementations for Generic Types Source: https://docs.rs/interception/0.1.2/interception/enum Showcases blanket implementations for generic types, demonstrating how traits like `Any`, `Borrow`, `BorrowMut`, `CloneToUninit`, `From`, `Into`, `ToOwned`, `TryFrom`, and `TryInto` are applied to generic contexts, often leveraging existing trait bounds. ```rust impl Any for T where T: 'static + ?Sized impl Borrow for T where T: ?Sized impl BorrowMut for T where T: ?Sized impl CloneToUninit for T where T: Clone impl From for T impl Into for T where U: From impl ToOwned for T where T: Clone impl TryFrom for T where U: Into impl TryInto for T where U: TryFrom ``` -------------------------------- ### Rust: Generic From and Into Conversions Source: https://docs.rs/interception/0.1.2/interception/struct Demonstrates generic implementations of `From` for `T` and `Into` for `T` where `U` implements `From`. These enable straightforward type conversions. ```rust impl From for T { fn from(t: T) -> T } impl Into for T where U: From, { fn into(self) -> U } ``` -------------------------------- ### Wait for Input Event (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Blocks execution until an input event occurs on any monitored device and returns the device handle. ```rust pub fn wait(&self) -> Device { unsafe { raw::interception_wait(self.ctx) } } ``` -------------------------------- ### Rust: MouseFlags methods for creating flag sets Source: https://docs.rs/interception/0.1.2/interception/struct Provides methods for creating MouseFlags sets, including an empty set and a set with all flags. These methods simplify the initialization of flag states. ```rust pub const fn empty() -> Self Returns an empty set of flags. ``` ```rust pub const fn all() -> Self Returns the set containing all flags. ``` -------------------------------- ### Convert Interception Keyboard Stroke to Raw Source: https://docs.rs/interception/0.1.2/src/interception/lib Implements the `TryFrom` trait to convert the library's `Stroke::Keyboard` variant back into a raw `interception_sys::InterceptionKeyStroke`. This facilitates sending modified keyboard events. ```rust impl TryFrom for raw::InterceptionKeyStroke { type Error = &'static str; fn try_from(stroke: Stroke) -> Result { if let Stroke::Keyboard { code, state, information, } = stroke { Ok(raw::InterceptionKeyStroke { code: code.into(), // Assuming ScanCode has an into() for raw::InterceptionKeyStroke state: state.bits(), information: information, }) } else { Err("Stroke must be a keyboard stroke") } } } ``` -------------------------------- ### Convert Raw Keyboard Stroke to Interception Stroke Source: https://docs.rs/interception/0.1.2/src/interception/lib Implements the `TryFrom` trait to convert a raw `interception_sys::InterceptionKeyStroke` into the library's `Stroke::Keyboard` variant. Handles potential errors from invalid bit flags or scan codes. ```rust impl TryFrom for Stroke { type Error = &'static str; fn try_from(raw_stroke: raw::InterceptionKeyStroke) -> Result { let state = match KeyState::from_bits(raw_stroke.state) { Some(state) => state, None => return Err("Extra bits in raw keyboard state"), }; let code = match ScanCode::try_from(raw_stroke.code) { Ok(code) => code, Err(_) => ScanCode::Esc, // Default to Esc on error }; Ok(Stroke::Keyboard { code: code, state: state, information: raw_stroke.information, }) } } ``` -------------------------------- ### Rust: Generic TryFrom and TryInto Conversions Source: https://docs.rs/interception/0.1.2/interception/struct Illustrates generic implementations of `TryFrom` for `T` and `TryInto` for `T`. These traits handle fallible type conversions, returning a `Result`. ```rust impl TryFrom for T where U: Into, { type Error = Infallible; fn try_from(value: U) -> Result>::Error> } impl TryInto for T where U: TryFrom, { type Error = >::Error; fn try_into(self) -> Result>::Error> } ``` -------------------------------- ### PartialOrd Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Provides partial ordering comparisons for MouseFlags values, including methods for less than (`lt`), less than or equal to (`le`), greater than (`gt`), and greater than or equal to (`ge`). ```rust fn partial_cmp(&self, other: &MouseFlags) -> Option ``` ```rust fn lt(&self, other: &Rhs) -> bool ``` ```rust fn le(&self, other: &Rhs) -> bool ``` ```rust fn gt(&self, other: &Rhs) -> bool ``` ```rust fn ge(&self, other: &Rhs) -> bool ``` -------------------------------- ### Define Keyboard States and Filters with Bitflags Source: https://docs.rs/interception/0.1.2/src/interception/lib Defines bitflags for keyboard states (e.g., key down/up, extended key codes) and filters (similar to states but used for filtering). These enable granular control over keyboard input events. ```rust pub struct KeyState: u16 { pub const DOWN: u16 = 0; pub const UP: u16 = 1; pub const E0: u16 = 2; pub const E1: u16 = 3; pub const TERMSRV_SET_LED: u16 = 8; pub const TERMSRV_SHADOW: u16 = 16; pub const TERMSRV_VKPACKET: u16 = 32; } pub struct KeyFilter: u16 { pub const DOWN: u16 = 1; pub const UP: u16 = 2; pub const E0: u16 = 4; pub const E1: u16 = 8; pub const TERMSRV_SET_LED: u16 = 16; pub const TERMSRV_SHADOW: u16 = 32; pub const TERMSRV_VKPACKET: u16 = 64; } ``` -------------------------------- ### Define Mouse States and Flags with Bitflags Source: https://docs.rs/interception/0.1.2/src/interception/lib Defines bitflags for mouse states (e.g., button presses, wheel movements, move events) and flags (e.g., relative/absolute movement, virtual desktop). These allow for efficient representation and manipulation of mouse input data. ```rust pub struct MouseState: u16 { pub const LEFT_BUTTON_DOWN: u16 = 1; pub const LEFT_BUTTON_UP: u16 = 2; pub const RIGHT_BUTTON_DOWN: u16 = 4; pub const RIGHT_BUTTON_UP: u16 = 8; pub const MIDDLE_BUTTON_DOWN: u16 = 16; pub const MIDDLE_BUTTON_UP: u16 = 32; pub const BUTTON_4_DOWN: u16 = 64; pub const BUTTON_4_UP: u16 = 128; pub const BUTTON_5_DOWN: u16 = 256; pub const BUTTON_5_UP: u16 = 512; pub const WHEEL: u16 = 1024; pub const HWHEEL: u16 = 2048; // MouseFilter only pub const MOVE: u16 = 4096; } pub type MouseFilter = MouseState; pub struct MouseFlags: u16 { pub const MOVE_RELATIVE: u16 = 0; pub const MOVE_ABSOLUTE: u16 = 1; pub const VIRTUAL_DESKTOP: u16 = 2; pub const ATTRIBUTES_CHANGED: u16 = 4; pub const MOVE_NO_COALESCE: u16 = 8; pub const TERMSRV_SRC_SHADOW: u16 = 256; } ``` -------------------------------- ### Convert Raw Mouse Stroke to Interception Stroke Source: https://docs.rs/interception/0.1.2/src/interception/lib Implements the `TryFrom` trait to convert a raw `interception_sys::InterceptionMouseStroke` into the library's `Stroke::Mouse` variant. Handles potential errors from invalid bit flags. ```rust impl TryFrom for Stroke { type Error = &'static str; fn try_from(raw_stroke: raw::InterceptionMouseStroke) -> Result { let state = match MouseState::from_bits(raw_stroke.state) { Some(state) => state, None => return Err("Extra bits in raw mouse state"), }; let flags = match MouseFlags::from_bits(raw_stroke.flags) { Some(flags) => flags, None => return Err("Extra bits in raw mouse flags"), }; Ok(Stroke::Mouse { state: state, flags: flags, rolling: raw_stroke.rolling, x: raw_stroke.x, y: raw_stroke.y, information: raw_stroke.information, }) } } ``` -------------------------------- ### Internal Send Helper (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib A generic internal helper function to send strokes to a device. It handles the conversion of generic `Stroke` types to specific raw stroke types. ```rust fn send_internal>(&self, device: Device, strokes: &[Stroke]) -> i32 { let mut raw_strokes = Vec::new(); for stroke in strokes { if let Ok(raw_stroke) = T::try_from(*stroke) { raw_strokes.push(raw_stroke) } } let ptr = raw_strokes.as_ptr(); let len = match u32::try_from(raw_strokes.len()) { Ok(l) => l, Err(_) => u32::MAX, }; unsafe { raw::interception_send(self.ctx, device, std::mem::transmute(ptr), len) } } ``` -------------------------------- ### Rust: Implementation of Binary trait for MouseFlags Source: https://docs.rs/interception/0.1.2/interception/struct Shows the implementation of the `Binary` trait for `MouseFlags`, which enables formatting the flags for binary representation. This is useful for debugging or low-level analysis. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. Read more ``` -------------------------------- ### PartialEq Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Enables equality and inequality comparisons for MouseFlags values using the `PartialEq` trait. ```rust fn eq(&self, other: &MouseFlags) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Internal Receive Helper (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib A generic internal helper function to receive strokes from a device. It manages the conversion from raw stroke types to the generic `Stroke` type. ```rust fn receive_internal + Default + Copy>( &self, device: Device, strokes: &mut [Stroke], ) -> i32 { let mut raw_strokes: Vec = Vec::with_capacity(strokes.len()); raw_strokes.resize_with(strokes.len(), Default::default); let ptr = raw_strokes.as_ptr(); let len = match u32::try_from(raw_strokes.len()) { Ok(l) => l, Err(_) => u32::MAX, }; let num_read = unsafe { raw::interception_receive(self.ctx, device, std::mem::transmute(ptr), len) }; let mut num_valid: i32 = 0; for i in 0..num_read { if let Ok(stroke) = raw_strokes[i as usize].try_into() { strokes[num_valid as usize] = stroke; num_valid += 1; } } num_valid } ``` -------------------------------- ### Convert Interception Mouse Stroke to Raw Source: https://docs.rs/interception/0.1.2/src/interception/lib Implements the `TryFrom` trait to convert the library's `Stroke::Mouse` variant back into a raw `interception_sys::InterceptionMouseStroke`. This is useful for sending modified strokes. ```rust impl TryFrom for raw::InterceptionMouseStroke { type Error = &'static str; fn try_from(stroke: Stroke) -> Result { if let Stroke::Mouse { state, flags, rolling, x, y, information, } = stroke { Ok(raw::InterceptionMouseStroke { state: state.bits(), flags: flags.bits(), rolling: rolling, x: x, y: y, information: information, }) } else { Err("Stroke must be a mouse stroke") } } } ``` -------------------------------- ### Send Input Strokes (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Sends a slice of input strokes (mouse or keyboard) to a specific device. Returns the number of strokes actually sent. ```rust pub fn send(&self, device: Device, strokes: &[Stroke]) -> i32 { if is_mouse(device) { self.send_internal::(device, strokes) } else if is_keyboard(device) { self.send_internal::(device, strokes) } else { 0 } } ``` -------------------------------- ### MouseFlags Constants and Methods Source: https://docs.rs/interception/0.1.2/interception/struct Details on the constants and methods available for the MouseFlags struct, including flag manipulation and querying. ```APIDOC ## Struct MouseFlags ### Description Represents a set of flags for mouse events. ### Fields ```rust pub struct MouseFlags { /* private fields */ } ``` ## Constants - **MOVE_RELATIVE**: Represents a relative mouse movement. - **MOVE_ABSOLUTE**: Represents an absolute mouse movement. - **VIRTUAL_DESKTOP**: Indicates the movement is relative to a virtual desktop. - **ATTRIBUTES_CHANGED**: Signals that attributes have changed. - **MOVE_NO_COALESCE**: Prevents coalescing of mouse move events. - **TERMSRV_SRC_SHADOW**: Indicates the source is a Terminal Services shadow. ## Methods - **`empty()`**: Returns an empty set of flags. - **Signature**: `pub const fn empty() -> Self` - **`all()`**: Returns the set containing all possible flags. - **Signature**: `pub const fn all() -> Self` - **`bits()`**: Returns the raw `u16` value of the flags. - **Signature**: `pub const fn bits(&self) -> u16` - **`from_bits(bits: u16)`**: Converts from underlying bit representation, returning `None` if invalid bits are present. - **Signature**: `pub const fn from_bits(bits: u16) -> Option` - **`from_bits_truncate(bits: u16)`**: Converts from underlying bit representation, dropping any invalid bits. - **Signature**: `pub const fn from_bits_truncate(bits: u16) -> Self` - **`from_bits_unchecked(bits: u16)`**: Converts from underlying bit representation, preserving all bits (unsafe). - **Signature**: `pub const unsafe fn from_bits_unchecked(bits: u16) -> Self` - **Safety**: The caller must ensure that all bits correspond to defined flags or are valid for the type. - **`is_empty()`**: Returns `true` if no flags are currently stored. - **Signature**: `pub const fn is_empty(&self) -> bool` - **`is_all()`**: Returns `true` if all flags are currently set. - **Signature**: `pub const fn is_all(&self) -> bool` - **`intersects(other: Self)`**: Returns `true` if there are flags common to both sets. - **Signature**: `pub const fn intersects(&self, other: Self) -> bool` - **`contains(other: Self)`**: Returns `true` if all flags in `other` are contained within `self`. - **Signature**: `pub const fn contains(&self, other: Self) -> bool` - **`insert(other: Self)`**: Inserts the specified flags in-place. - **Signature**: `pub fn insert(&mut self, other: Self)` - **`remove(other: Self)`**: Removes the specified flags in-place. - **Signature**: `pub fn remove(&mut self, other: Self)` - **`toggle(other: Self)`**: Toggles the specified flags in-place. - **Signature**: `pub fn toggle(&mut self, other: Self)` - **`set(other: Self, value: bool)`**: Inserts or removes flags based on the `value` parameter. - **Signature**: `pub fn set(&mut self, other: Self, value: bool)` - **`intersection(other: Self)`**: Returns the intersection between two sets of flags. - **Signature**: `pub const fn intersection(self, other: Self) -> Self` - **`union(other: Self)`**: Returns the union between two sets of flags. - **Signature**: `pub const fn union(self, other: Self) -> Self` - **`difference(other: Self)`**: Returns the difference between two sets of flags. - **Signature**: `pub const fn difference(self, other: Self) -> Self` - **`symmetric_difference(other: Self)`**: Returns the symmetric difference between two sets of flags. - **Signature**: `pub const fn symmetric_difference(self, other: Self) -> Self` - **`complement()`**: Returns the complement of the set of flags. - **Signature**: `pub const fn complement(self) -> Self` ## Trait Implementations ### `Binary` for `MouseFlags` - **`fmt(f: &mut Formatter<'_>)`**: Formats the value using the given formatter. - **Signature**: `fn fmt(&self, f: &mut Formatter<'_>) -> Result` ### `BitAnd` for `MouseFlags` - **`bitand(self, other: Self)`**: Returns the intersection between the two sets of flags. - **Signature**: `fn bitand(self, other: Self) -> Self` - **Output Type**: `MouseFlags` ### `BitAndAssign` for `MouseFlags` (No specific methods documented for this trait in the provided text.) ``` -------------------------------- ### Set Device Filter (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Sets a filter for input events based on a predicate and a filter value. This function allows for custom filtering of events for devices. ```rust pub fn set_filter(&self, predicate: Predicate, filter: Filter) { let filter = match filter { Filter::MouseFilter(filter) => filter.bits(), Filter::KeyFilter(filter) => filter.bits(), }; unsafe { let predicate = std::mem::transmute(Some(predicate)); raw::interception_set_filter(self.ctx, predicate, filter) } } ``` -------------------------------- ### Ord Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Provides total ordering comparisons for MouseFlags values, including methods for comparison (`cmp`), finding the maximum (`max`), minimum (`min`), and clamping within a range (`clamp`). ```rust fn cmp(&self, other: &MouseFlags) -> Ordering ``` ```rust fn max(self, other: Self) -> Self where Self: Sized, ``` ```rust fn min(self, other: Self) -> Self where Self: Sized, ``` ```rust fn clamp(self, min: Self, max: Self) -> Self where Self: Sized, ``` -------------------------------- ### Wait for Input Event with Timeout (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Blocks execution until an input event occurs or a specified duration elapses. Returns the device handle if an event occurs, otherwise indicates a timeout. ```rust pub fn wait_with_timeout(&self, duration: Duration) -> Device { let millis = match u32::try_from(duration.as_millis()) { Ok(m) => m, Err(_) => u32::MAX, }; unsafe { raw::interception_wait_with_timeout(self.ctx, millis) } } ``` -------------------------------- ### Hash Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Provides methods for hashing MouseFlags values, allowing them to be used in hash-based collections. Includes `hash` for individual values and `hash_slice` for slices. ```rust fn hash<__H: Hasher>(&self, state: &mut __H) ``` ```rust fn hash_slice(data: &[Self], state: &mut H) where H: Hasher, Self: Sized, ``` -------------------------------- ### Re-export interception_sys as raw Source: https://docs.rs/interception/0.1.2/interception This code snippet illustrates aliasing the 'interception_sys' crate to 'raw' within the 'interception' crate for simplified access to system-level functions. ```rust pub use interception_sys as raw; ``` -------------------------------- ### Implement Equality Checks for ScanCode in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Provides methods to compare ScanCode values for equality (`eq`) and inequality (`ne`). The `eq` method tests if two ScanCode instances have the same value, and it's used by the `==` operator. The `ne` method tests for inequality, with a default implementation that is usually sufficient. ```rust fn eq(&self, other: &ScanCode) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. ``` ```rust fn ne(&self, other: &Rhs) -> bool Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. ``` -------------------------------- ### Rust: Generic Borrow and BorrowMut Methods Source: https://docs.rs/interception/0.1.2/interception/struct Illustrates generic implementations of `Borrow` and `BorrowMut` traits for type `T`. These traits provide immutable and mutable borrowing capabilities respectively. ```rust impl Borrow for T where T: ?Sized, { fn borrow(&self) -> &T } impl BorrowMut for T where T: ?Sized, { fn borrow_mut(&mut self) -> &mut T } ``` -------------------------------- ### Rust: MouseFlags methods for converting from bits Source: https://docs.rs/interception/0.1.2/interception/struct Includes methods for converting raw `u16` bit values into MouseFlags sets. It supports safe conversion with optional return and conversion that truncates unknown bits. ```rust pub const fn from_bits(bits: u16) -> Option Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag. ``` ```rust pub const fn from_bits_truncate(bits: u16) -> Self Convert from underlying bit representation, dropping any bits that do not correspond to flags. ``` ```rust pub unsafe fn from_bits_unchecked(bits: u16) -> Self Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag). ##### §Safety The caller of the `bitflags!` macro can chose to allow or disallow extra bits for their bitflags type. The caller of `from_bits_unchecked()` has to ensure that all bits correspond to a defined flag or that extra bits are valid for this bitflags type. ``` -------------------------------- ### Rust: Implementation of BitAnd trait for MouseFlags Source: https://docs.rs/interception/0.1.2/interception/struct Demonstrates the implementation of the `BitAnd` trait for `MouseFlags`, allowing the use of the `&` operator for calculating the intersection of two flag sets. ```rust fn bitand(self, other: Self) -> Self Returns the intersection between the two sets of flags. ``` ```rust type Output = MouseFlags; The resulting type after applying the `&` operator. ``` -------------------------------- ### Rust: Generic to_owned Method Source: https://docs.rs/interception/0.1.2/interception/struct Shows the generic implementation of the `to_owned` method for types `T` that implement `Clone`. This allows creating owned data from borrowed data. ```rust impl ToOwned for T where T: Clone, { type Owned = T; fn to_owned(&self) -> T; fn clone_into(&self, target: &mut T); } ``` -------------------------------- ### Rust ScanCode PartialEq Implementation Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Implements the `PartialEq` trait for `ScanCode`, allowing direct comparison of `ScanCode` enum variants for equality. This is fundamental for logical operations involving scan codes. ```rust impl PartialEq for ScanCode ``` -------------------------------- ### Receive Input Strokes (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Receives input strokes from a specified device into a mutable slice. Returns the number of strokes successfully read from the device. ```rust pub fn receive(&self, device: Device, strokes: &mut [Stroke]) -> i32 { if is_mouse(device) { self.receive_internal::(device, strokes) } else if is_keyboard(device) { self.receive_internal::(device, strokes) } else { 0 } } ``` -------------------------------- ### Clone into uninitialized memory in Rust (Nightly) Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Provides an experimental, nightly-only `CloneToUninit` trait for cloning data directly into uninitialized memory. The `clone_to_uninit` method performs copy-assignment from `self` to a raw pointer `dest`. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### Check if Device is Invalid (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib A C-style extern function that checks if a given `Device` is invalid according to the Interception library. It returns `true` if the device is invalid, `false` otherwise. ```rust pub extern "C" fn is_invalid(device: Device) -> bool { unsafe { raw::interception_is_invalid(device) != 0 } } ``` -------------------------------- ### Check if Device is a Keyboard (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib A C-style extern function that determines if a specified `Device` is a keyboard. It returns `true` if the device is a keyboard, `false` otherwise. ```rust pub extern "C" fn is_keyboard(device: Device) -> bool { unsafe { raw::interception_is_keyboard(device) != 0 } } ``` -------------------------------- ### Re-export interception_sys Source: https://docs.rs/interception/0.1.2/interception This code snippet demonstrates how the 'interception_sys' crate is re-exported within the 'interception' crate, making its functionalities directly accessible. ```rust pub extern crate interception_sys; ``` -------------------------------- ### Re-export interception_sys Source: https://docs.rs/interception/0.1.2/interception/index Re-exports the 'interception_sys' crate, aliasing it as 'raw' for direct access to low-level functionalities. Also re-exports 'ScanCode' from the 'scancode' crate. ```Rust pub extern crate interception_sys; pub use scancode::ScanCode; pub use interception_sys as raw; ``` -------------------------------- ### Extend Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Allows extending a MouseFlags collection with elements from an iterator or a single element. Includes nightly-only experimental APIs for `extend_one` and `extend_reserve`. ```rust fn extend>(&mut self, iterator: T) ``` ```rust fn extend_one(&mut self, item: A) ``` ```rust fn extend_reserve(&mut self, additional: usize) ``` -------------------------------- ### Convert using TryInto in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Implements the generic `TryInto` trait, allowing conversion from type `T` to type `U` if `U` implements `TryFrom`. It defines an `Error` type and a `try_into` method for the conversion process. ```rust type Error = >::Error The type returned in the event of a conversion error. ``` ```rust fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Rust ScanCode Clone Implementation Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Provides implementations for cloning `ScanCode` values. The `clone` method creates a duplicate of the enum value, and `clone_from` performs copy-assignment. These are essential for value manipulation and assignment. ```rust impl Clone for ScanCode { fn clone(&self) -> ScanCode; fn clone_from(&mut self, source: &Self); } ``` -------------------------------- ### Rust Trait Implementation: TryFrom for InterceptionMouseStroke Source: https://docs.rs/interception/0.1.2/interception/enum Enables conversion from the `Stroke` enum to `InterceptionMouseStroke`. This is crucial for translating internal `Stroke` representations into a format suitable for the interception driver. Error management is provided. ```rust impl TryFrom for InterceptionMouseStroke type Error = &'static str fn try_from(stroke: Stroke) -> Result ``` -------------------------------- ### Clone Implementation for MouseFlags (Rust) Source: https://docs.rs/interception/0.1.2/interception/struct Provides methods to create a duplicate of a MouseFlags value (`clone`) or perform copy-assignment from another MouseFlags value (`clone_from`). ```rust fn clone(&self) -> MouseFlags ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Serialize ScanCode to Serde Serializer in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Implements the `Serialize` trait for `ScanCode`, allowing it to be serialized into various formats using the Serde library. The `serialize` method takes a generic `Serializer` and returns a `Result` indicating success or failure. ```rust fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer, Serialize this value into the given Serde serializer. Read more ``` -------------------------------- ### Set Device Precedence (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib Sets the precedence level for a given device. This affects how input events from this device are handled by the interception layer. ```rust pub fn set_precedence(&self, device: Device, precedence: Precedence) { unsafe { raw::interception_set_precedence(self.ctx, device, precedence) } } ``` -------------------------------- ### Rust Trait Implementation: TryFrom for InterceptionKeyStroke Source: https://docs.rs/interception/0.1.2/interception/enum Allows conversion from the `Stroke` enum to `InterceptionKeyStroke`. This is useful for sending processed stroke data back to the interception system. Error handling is included for conversion failures. ```rust impl TryFrom for InterceptionKeyStroke type Error = &'static str fn try_from(stroke: Stroke) -> Result ``` -------------------------------- ### Rust: MouseFlags constants for bitflags Source: https://docs.rs/interception/0.1.2/interception/struct Provides constants for individual flags within the MouseFlags struct, such as MOVE_RELATIVE, MOVE_ABSOLUTE, VIRTUAL_DESKTOP, ATTRIBUTES_CHANGED, MOVE_NO_COALESCE, and TERMSRV_SRC_SHADOW. ```rust pub const MOVE_RELATIVE: Self ``` ```rust pub const MOVE_ABSOLUTE: Self ``` ```rust pub const VIRTUAL_DESKTOP: Self ``` ```rust pub const ATTRIBUTES_CHANGED: Self ``` ```rust pub const MOVE_NO_COALESCE: Self ``` ```rust pub const TERMSRV_SRC_SHADOW: Self ``` -------------------------------- ### Rust: MouseFlags Auto Trait Implementations Source: https://docs.rs/interception/0.1.2/interception/struct Demonstrates Auto Trait implementations for MouseFlags, including Copy, Eq, StructuralPartialEq, Freeze, RefUnwindSafe, Send, Sync, Unpin, and UnwindSafe. These traits enable basic functionality and thread safety guarantees. ```rust impl Copy for MouseFlags impl Eq for MouseFlags impl StructuralPartialEq for MouseFlags impl Freeze for MouseFlags impl RefUnwindSafe for MouseFlags impl Send for MouseFlags impl Sync for MouseFlags impl Unpin for MouseFlags impl UnwindSafe for MouseFlags ``` -------------------------------- ### Rust ScanCode Debug Implementation Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Implements the `Debug` trait for `ScanCode`, allowing enum values to be formatted for debugging purposes. The `fmt` method writes the value's representation to a formatter. ```rust impl Debug for ScanCode { fn fmt(&self, f: &mut Formatter<'_>) -> Result; } ``` -------------------------------- ### Check if Device is a Mouse (Rust) Source: https://docs.rs/interception/0.1.2/src/interception/lib A C-style extern function that checks if a given `Device` represents a mouse. It returns `true` if the device is a mouse, `false` otherwise. ```rust pub extern "C" fn is_mouse(device: Device) -> bool { unsafe { raw::interception_is_mouse(device) != 0 } } ``` -------------------------------- ### Rust: MouseFlags methods for set operations Source: https://docs.rs/interception/0.1.2/interception/struct Enables performing standard set operations on MouseFlags, such as intersection, union, difference, and symmetric difference. These operations allow for complex flag manipulation. ```rust pub const fn intersects(&self, other: Self) -> bool Returns `true` if there are flags common to both `self` and `other`. ``` ```rust pub const fn contains(&self, other: Self) -> bool Returns `true` if all of the flags in `other` are contained within `self`. ``` ```rust pub const fn intersection(self, other: Self) -> Self Returns the intersection between the flags in `self` and `other`. Specifically, the returned set contains only the flags which are present in _both_ `self` _and_ `other`. This is equivalent to using the `&` operator (e.g. `ops::BitAnd`), as in `flags & other`. ``` ```rust pub const fn union(self, other: Self) -> Self Returns the union of between the flags in `self` and `other`. Specifically, the returned set contains all flags which are present in _either_ `self` _or_ `other`, including any which are present in both (see `Self::symmetric_difference` if that is undesirable). This is equivalent to using the `|` operator (e.g. `ops::BitOr`), as in `flags | other`. ``` ```rust pub const fn difference(self, other: Self) -> Self Returns the difference between the flags in `self` and `other`. Specifically, the returned set contains all flags present in `self`, except for the ones present in `other`. It is also conceptually equivalent to the “bit-clear” operation: `flags & !other` (and this syntax is also supported). This is equivalent to using the `-` operator (e.g. `ops::Sub`), as in `flags - other`. ``` ```rust pub const fn symmetric_difference(self, other: Self) -> Self Returns the symmetric difference between the flags in `self` and `other`. Specifically, the returned set contains the flags present which are present in `self` or `other`, but that are not present in both. Equivalently, it contains the flags present in _exactly one_ of the sets `self` and `other`. This is equivalent to using the `^` operator (e.g. `ops::BitXor`), as in `flags ^ other`. ``` ```rust pub const fn complement(self) -> Self Returns the complement of this set of flags. Specifically, the returned set contains all the flags which are not set in `self`, but which are allowed for this type. Alternatively, it can be thought of as the set difference between `Self::all()` and `self` (e.g. `Self::all() - self`) This is equivalent to using the `!` operator (e.g. `ops::Not`), as in `!flags`. ``` -------------------------------- ### Rust ScanCode Hash Implementation Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Provides hashing capabilities for `ScanCode` values, enabling their use in hash-based collections like `HashMap` and `HashSet`. The `hash` method incorporates the enum's value into a hasher, and `hash_slice` handles slices. ```rust impl Hash for ScanCode { fn hash<__H: Hasher>(&self, state: &mut __H); fn hash_slice(data: &[Self], state: &mut H) where H: Hasher, Self: Sized; } ``` -------------------------------- ### Re-export scancode::ScanCode Source: https://docs.rs/interception/0.1.2/interception This code snippet shows the re-export of 'scancode::ScanCode' from the 'scancode' crate, allowing direct use of ScanCode within the 'interception' crate. ```rust pub use scancode::ScanCode; ``` -------------------------------- ### Convert u16 to ScanCode using TryFrom in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Enables conversion of a `u16` primitive into a `ScanCode` using the `TryFrom` trait. It defines an associated `Error` type, `TryFromPrimitiveError`, for handling conversion failures. The `try_from` function attempts the conversion. ```rust type Error = TryFromPrimitiveError The type returned in the event of a conversion error. ``` ```rust fn try_from(number: u16) -> Result> Performs the conversion. ``` -------------------------------- ### Rust Trait Implementation: TryFrom for Stroke Source: https://docs.rs/interception/0.1.2/interception/enum Facilitates conversion from `InterceptionMouseStroke` to the `Stroke` enum. Similar to the key stroke conversion, it manages potential errors and returns a `Result` indicating success or failure. ```rust impl TryFrom for Stroke type Error = &'static str fn try_from(raw_stroke: InterceptionMouseStroke) -> Result ``` -------------------------------- ### Define Unified Stroke Enum for Mouse and Keyboard Source: https://docs.rs/interception/0.1.2/src/interception/lib Defines a `Stroke` enum to represent either a mouse stroke (with state, flags, rolling, coordinates) or a keyboard stroke (with scan code, state). This unifies input event representation. ```rust pub enum Stroke { Mouse { state: MouseState, flags: MouseFlags, rolling: i16, x: i32, y: i32, information: u32, }, Keyboard { code: ScanCode, state: KeyState, information: u32, }, } ``` -------------------------------- ### Implement TryFromPrimitive for ScanCode in Rust Source: https://docs.rs/interception/0.1.2/interception/scancode/enum Provides a `TryFromPrimitive` implementation for `ScanCode`. This includes defining the `Primitive` type as `u16` and a `try_from_primitive` function to convert from the primitive type. ```rust const NAME: &'static str = "ScanCode" ``` ```rust type Primitive = u16 ``` ```rust fn try_from_primitive( number: Self::Primitive, ) -> Result> ``` -------------------------------- ### Rust Trait Implementation: TryFrom for Stroke Source: https://docs.rs/interception/0.1.2/interception/enum Enables conversion from `InterceptionKeyStroke` to the `Stroke` enum. This implementation handles potential errors during conversion, returning a `Result` with a static string error message on failure. ```rust impl TryFrom for Stroke type Error = &'static str fn try_from(raw_stroke: InterceptionKeyStroke) -> Result ```