pub struct Device { /* fields omitted */ }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.
This type specifically is a wrapper over RawDevice,that synchronizes with the kernel’s
state when events are dropped.
If fetch_events() isn’t called often enough and the kernel drops events from its internal
buffer, synthetic events will be injected into the iterator returned by fetch_events() and
Device::cached_state() will be kept up to date when fetch_events() is called.
Implementations
Opens a device, given its system path.
Paths are typically something like /dev/input/event0.
Returns the synchronization engine’s current understanding (cache) of the device state.
Note that this represents the internal cache of the synchronization engine as of the last
entry that was pulled out. The advantage to calling this instead of invoking
get_key_state
and the like directly is speed: because reading this cache doesn’t require any syscalls it’s
easy to do inside a tight loop. The downside is that if the stream is not being driven quickly,
this can very quickly get desynchronized from the kernel and provide inaccurate data.
Returns the device’s physical location, either as set by the caller or as read from the kernel.
Returns the user-defined “unique name” of the device, if one has been set.
Returns a struct containing bustype, vendor, product, and version identifiers
Returns a struct containing the delay and period for auto repeat
Update the delay and period for autorepeat
Retrieve the scancode for a keycode, if any
Retrieve the keycode and scancode by index, starting at 0
Update a scancode. The return value is the previous keycode
Update a scancode by index. The return value is the previous keycode
Returns the set of supported “properties” for the device (see INPUT_PROP_* in kernel headers)
Returns a tuple of the driver version containing major, minor, rev
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.
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));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));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));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));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.
Returns a set of supported “miscellaneous” capabilities.
Aside from vendor-specific key scancodes, most of these are uncommon.
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.
Retrieve the current keypress state directly via kernel syscall.
Retrieve the current absolute axis state directly via kernel syscall.
Retrieve the current switch state directly via kernel syscall.
Retrieve the current LED state directly via kernel syscall.
Fetches and returns events from the kernel ring buffer, 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. Will insert “fake” events.
Grab the device through a kernel syscall.
This prevents other clients (including kernel-internal ones such as rfkill) from receiving events from this device.
Send an event to the device.
Events that are typically sent to devices are EventType::LED (turn device LEDs on and off), EventType::SOUND (play a sound on the device) and EventType::FORCEFEEDBACK (play force feedback effects on the device, i.e. rumble).
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Device
impl UnwindSafe for Device
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self to use its Binary implementation when Debug-formatted. Read more
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self to use its Display implementation when
Debug-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self to use its LowerExp implementation when
Debug-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self to use its LowerHex implementation when
Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted. Read more
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self to use its Pointer implementation when
Debug-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self to use its UpperExp implementation when
Debug-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self to use its UpperHex implementation when
Debug-formatted. Read more
fn fmt_list(self) -> FmtList<Self> where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self> where
&'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.borrow() into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.borrow_mut() into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.as_ref() into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.as_mut() into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.deref() into the pipe function.
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B> of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut() only in debug builds, and is erased in release
builds. Read more
