Struct evdev::Device[][src]

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 name as read from the kernel.

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.

Ungrab the device through a kernel syscall.

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

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

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

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.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.