pub struct RawDevice { /* private fields */ }Expand description
A physical or virtual device supported by evdev.
Each device corresponds to a path typically found in /dev/input, and supports access via
one or more “types”. For example, an optical mouse has buttons that are represented by “keys”,
and reflects changes in its position via “relative axis” reports.
Implementations§
Source§impl RawDevice
impl RawDevice
Sourcepub fn open(path: impl AsRef<Path>) -> Result<RawDevice>
pub fn open(path: impl AsRef<Path>) -> Result<RawDevice>
Opens a device, given its system path.
Paths are typically something like /dev/input/event0.
Sourcepub fn physical_path(&self) -> Option<&str>
pub fn physical_path(&self) -> Option<&str>
Returns the device’s physical location, either as set by the caller or as read from the kernel.
Sourcepub fn unique_name(&self) -> Option<&str>
pub fn unique_name(&self) -> Option<&str>
Returns the user-defined “unique name” of the device, if one has been set.
Sourcepub fn input_id(&self) -> InputId
pub fn input_id(&self) -> InputId
Returns a struct containing bustype, vendor, product, and version identifiers
Sourcepub fn get_auto_repeat(&self) -> Option<AutoRepeat>
pub fn get_auto_repeat(&self) -> Option<AutoRepeat>
Returns the current auto repeat settings
Sourcepub fn properties(&self) -> &AttributeSetRef<PropType>
pub fn properties(&self) -> &AttributeSetRef<PropType>
Returns the set of supported “properties” for the device (see INPUT_PROP_* in kernel headers)
Sourcepub fn driver_version(&self) -> (u8, u8, u8)
pub fn driver_version(&self) -> (u8, u8, u8)
Returns a tuple of the driver version containing major, minor, rev
Sourcepub fn supported_events(&self) -> &AttributeSetRef<EventType>
pub fn supported_events(&self) -> &AttributeSetRef<EventType>
Returns a set of the event types supported by this device (Key, Switch, etc)
If you’re interested in the individual keys or switches supported, it’s probably easier
to just call the appropriate supported_* function instead.
Sourcepub fn supported_keys(&self) -> Option<&AttributeSetRef<Key>>
pub fn supported_keys(&self) -> Option<&AttributeSetRef<Key>>
Returns the set of supported keys reported by the device.
For keyboards, this is the set of all possible keycodes the keyboard may emit. Controllers, mice, and other peripherals may also report buttons as keys.
§Examples
use evdev::{Device, Key};
let device = Device::open("/dev/input/event0")?;
// Does this device have an ENTER key?
let supported = device.supported_keys().map_or(false, |keys| keys.contains(Key::KEY_ENTER));Sourcepub fn supported_relative_axes(
&self,
) -> Option<&AttributeSetRef<RelativeAxisType>>
pub fn supported_relative_axes( &self, ) -> Option<&AttributeSetRef<RelativeAxisType>>
Returns the set of supported “relative axes” reported by the device.
Standard mice will generally report REL_X and REL_Y along with wheel if supported.
§Examples
use evdev::{Device, RelativeAxisType};
let device = Device::open("/dev/input/event0")?;
// Does the device have a scroll wheel?
let supported = device
.supported_relative_axes()
.map_or(false, |axes| axes.contains(RelativeAxisType::REL_WHEEL));Sourcepub fn supported_absolute_axes(
&self,
) -> Option<&AttributeSetRef<AbsoluteAxisType>>
pub fn supported_absolute_axes( &self, ) -> Option<&AttributeSetRef<AbsoluteAxisType>>
Returns the set of supported “absolute axes” reported by the device.
These are most typically supported by joysticks and touchpads.
§Examples
use evdev::{Device, AbsoluteAxisType};
let device = Device::open("/dev/input/event0")?;
// Does the device have an absolute X axis?
let supported = device
.supported_absolute_axes()
.map_or(false, |axes| axes.contains(AbsoluteAxisType::ABS_X));Sourcepub fn supported_switches(&self) -> Option<&AttributeSetRef<SwitchType>>
pub fn supported_switches(&self) -> Option<&AttributeSetRef<SwitchType>>
Returns the set of supported switches reported by the device.
These are typically used for things like software switches on laptop lids (which the system reacts to by suspending or locking), or virtual switches to indicate whether a headphone jack is plugged in (used to disable external speakers).
§Examples
use evdev::{Device, SwitchType};
let device = Device::open("/dev/input/event0")?;
// Does the device report a laptop lid switch?
let supported = device
.supported_switches()
.map_or(false, |axes| axes.contains(SwitchType::SW_LID));Sourcepub fn supported_leds(&self) -> Option<&AttributeSetRef<LedType>>
pub fn supported_leds(&self) -> Option<&AttributeSetRef<LedType>>
Returns a set of supported LEDs on the device.
Most commonly these are state indicator lights for things like Scroll Lock, but they can also be found in cameras and other devices.
Sourcepub fn misc_properties(&self) -> Option<&AttributeSetRef<MiscType>>
pub fn misc_properties(&self) -> Option<&AttributeSetRef<MiscType>>
Returns a set of supported “miscellaneous” capabilities.
Aside from vendor-specific key scancodes, most of these are uncommon.
Sourcepub fn supported_sounds(&self) -> Option<&AttributeSetRef<SoundType>>
pub fn supported_sounds(&self) -> Option<&AttributeSetRef<SoundType>>
Returns the set of supported simple sounds supported by a device.
You can use these to make really annoying beep sounds come from an internal self-test speaker, for instance.
Sourcepub fn fetch_events(&mut self) -> Result<impl Iterator<Item = InputEvent> + '_>
pub fn fetch_events(&mut self) -> Result<impl Iterator<Item = InputEvent> + '_>
Fetches and returns events from the kernel ring buffer without doing synchronization on SYN_DROPPED.
By default this will block until events are available. Typically, users will want to call this in a tight loop within a thread.
Sourcepub fn get_key_state(&self) -> Result<AttributeSet<Key>>
pub fn get_key_state(&self) -> Result<AttributeSet<Key>>
Retrieve the current keypress state directly via kernel syscall.
Sourcepub fn get_abs_state(&self) -> Result<[input_absinfo; 64]>
pub fn get_abs_state(&self) -> Result<[input_absinfo; 64]>
Retrieve the current absolute axis state directly via kernel syscall.
Sourcepub fn get_switch_state(&self) -> Result<AttributeSet<SwitchType>>
pub fn get_switch_state(&self) -> Result<AttributeSet<SwitchType>>
Retrieve the current switch state directly via kernel syscall.
Sourcepub fn get_led_state(&self) -> Result<AttributeSet<LedType>>
pub fn get_led_state(&self) -> Result<AttributeSet<LedType>>
Retrieve the current LED state directly via kernel syscall.
Sourcepub fn update_key_state(&self, key_vals: &mut AttributeSet<Key>) -> Result<()>
pub fn update_key_state(&self, key_vals: &mut AttributeSet<Key>) -> Result<()>
Fetch the current kernel key state directly into the provided buffer.
If you don’t already have a buffer, you probably want
get_key_state instead.
Sourcepub fn update_abs_state(&self, abs_vals: &mut [input_absinfo; 64]) -> Result<()>
pub fn update_abs_state(&self, abs_vals: &mut [input_absinfo; 64]) -> Result<()>
Fetch the current kernel absolute axis state directly into the provided buffer.
If you don’t already have a buffer, you probably want
get_abs_state instead.
Sourcepub fn update_switch_state(
&self,
switch_vals: &mut AttributeSet<SwitchType>,
) -> Result<()>
pub fn update_switch_state( &self, switch_vals: &mut AttributeSet<SwitchType>, ) -> Result<()>
Fetch the current kernel switch state directly into the provided buffer.
If you don’t already have a buffer, you probably want
get_switch_state instead.
Sourcepub fn update_led_state(
&self,
led_vals: &mut AttributeSet<LedType>,
) -> Result<()>
pub fn update_led_state( &self, led_vals: &mut AttributeSet<LedType>, ) -> Result<()>
Fetch the current kernel LED state directly into the provided buffer.
If you don’t already have a buffer, you probably want
get_led_state instead.
Sourcepub fn update_auto_repeat(&mut self, repeat: &AutoRepeat) -> Result<()>
pub fn update_auto_repeat(&mut self, repeat: &AutoRepeat) -> Result<()>
Update the auto repeat delays
Sourcepub fn get_scancode_by_keycode(&self, keycode: u32) -> Result<Vec<u8>>
pub fn get_scancode_by_keycode(&self, keycode: u32) -> Result<Vec<u8>>
Retrieve the scancode for a keycode, if any
Sourcepub fn get_scancode_by_index(&self, index: u16) -> Result<(u32, Vec<u8>)>
pub fn get_scancode_by_index(&self, index: u16) -> Result<(u32, Vec<u8>)>
Retrieve the keycode and scancode by index, starting at 0
Sourcepub fn update_scancode_by_index(
&self,
index: u16,
keycode: u32,
scancode: &[u8],
) -> Result<u32>
pub fn update_scancode_by_index( &self, index: u16, keycode: u32, scancode: &[u8], ) -> Result<u32>
Update a scancode by index. The return value is the previous keycode
Sourcepub fn update_scancode(&self, keycode: u32, scancode: &[u8]) -> Result<u32>
pub fn update_scancode(&self, keycode: u32, scancode: &[u8]) -> Result<u32>
Update a scancode. The return value is the previous keycode
pub fn grab(&mut self) -> Result<()>
pub fn ungrab(&mut self) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawDevice
impl RefUnwindSafe for RawDevice
impl Send for RawDevice
impl Sync for RawDevice
impl Unpin for RawDevice
impl UnwindSafe for RawDevice
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
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
Source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
Source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
Source§impl<T> PipeRef for T
impl<T> PipeRef for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Source§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
tap in debug builds, and does nothing in release builds.Source§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Source§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
tap_mut in debug builds, and does nothing in release builds.Source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
Source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
Source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref in debug builds, and does nothing in release builds.Source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
Source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
Source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
Source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow in debug builds, and does nothing in release builds.Source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
Source§impl<T> TapDeref for T
impl<T> TapDeref for T
Source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref in debug builds, and does nothing in release builds.Source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self for modification.