Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

one connected box. every call checks what the box can do first, so nothing is faked and nothing is silently dropped. dropping it lets go of every button and key you were holding and closes the port

Implementations§

Source§

impl Device

Source

pub fn snapshot(&self) -> Arc<Snapshot> ⓘ

who the box is and what it can do, both read from the current connection. it can change after Reconnected

Source

pub fn move_by(&self, dx: i16, dy: i16) -> Result<()>

moves by counts, going through whatever smoothing the box has on

Source

pub fn move_now(&self, dx: i16, dy: i16) -> Result<()>

moves by counts on the box’s next report, skipping its smoothing for this move

Source

pub fn press(&self, button: Button) -> Result<()>

Source

pub fn release(&self, button: Button) -> Result<()>

Source

pub fn click(&self, button: Button) -> Result<()>

the box’s own click, or a click timed on the PC with the device’s ClickTiming if the box doesn’t have one

Source

pub fn click_with(&self, button: Button, click: Click) -> Result<()>

Source

pub fn press_key(&self, key: Key) -> Result<()>

holds a key down until release_key

Source

pub fn release_key(&self, key: Key) -> Result<()>

Source

pub fn tap_key(&self, key: Key) -> Result<()>

presses and lets go, timed by the box, or on the PC with the device’s ClickTiming if the box can’t

Source

pub fn tap_key_with(&self, key: Key, tap: Click) -> Result<()>

Source

pub fn press_media(&self, key: MediaKey) -> Result<()>

holds a media key down until release_media

Source

pub fn release_media(&self, key: MediaKey) -> Result<()>

Source

pub fn tap_media(&self, key: MediaKey) -> Result<()>

Source

pub fn tap_media_with(&self, key: MediaKey, tap: Click) -> Result<()>

Source

pub fn lock_button(&self, button: Button) -> Result<()>

keeps the physical button from reaching the PC until unlock_button. your own presses still go through and its events still come, so you can take the button over

Source

pub fn unlock_button(&self, button: Button) -> Result<()>

Source

pub fn lock_key(&self, key: Key) -> Result<()>

keeps the physical key from reaching the PC until unlock_key

Source

pub fn unlock_key(&self, key: Key) -> Result<()>

Source

pub fn lock_axis(&self, axis: Axis, direction: Direction) -> Result<()>

keeps physical motion one way or both ways along an axis from reaching the PC until unlock_axis. your own moves still go through

Source

pub fn unlock_axis(&self, axis: Axis, direction: Direction) -> Result<()>

unlocks that way along the axis and leaves the other way as it was. it also undoes a scale there

Source

pub fn scale_axis( &self, axis: Axis, direction: Direction, percent: i16, ) -> Result<()>

keeps percent of the physical motion one way or both ways along an axis, from -255 to 255. 100 leaves it alone, 0 blocks it and -100 inverts it. unlock_axis puts it back to 100

Source

pub fn wheel(&self, notches: i16) -> Result<()>

Source

pub fn pan(&self, notches: i16) -> Result<()>

horizontal scroll, positive goes right

Source

pub fn discard_pending_moves(&self) -> Result<()>

throws away the moves the box took but hasn’t sent yet. while the link is down it fails with Disconnected, and on a Medius with riding on, the moves it holds back are then only bounded by its riding window

Source

pub fn events(&self) -> Events ⓘ

a new receiver for all the input the box can stream, plus the connection events. the box only streams while at least one receiver is alive. just know that a receiver of keys sees every key typed on the keyboard behind the box, passwords included

Source

pub fn events_of(&self, kinds: EventKinds) -> Events ⓘ

a receiver for only these kinds of input, plus the connection events. the box streams what any receiver wants, so a receiver for buttons alone doesn’t make it send motion. a kind this box can’t stream gets one Rejected for it right away, and so does a kind the box refuses to switch on, even when an older receiver was just told the same thing. on Medius each kind is its own subscription, so the order between two kinds is only as good as their box time

Source

pub fn medius(&self) -> Option<Device>

the medius crate’s own device for this box, for everything only Medius does (clips, rendering, raw catch etc), and none on other boxes. it’s also where you get the polling rate (query_rate()) and the identity the box shows the PC (device_info())

to tell a mouse from a keyboard, check the capabilities and not the crate’s DeviceKind, which calls a mouse with a full key bitmap a keyboard

a clone you keep holds the port open after this device is gone. anybox doesn’t know about anything you press or lock through it, and its reset() lets go of and unlocks everything, including what you did through this device. events() comes back by itself after a Dropped, though a button held through the reset can show a second press with no release in between. anybox’s stream takes up to four of the box’s 32 catch entries, so if your own subscriptions fill the table the receiver gets a Rejected instead. once you’ve freed some, any receiver coming or going asks again. a reboot into a download target keeps the box down until you replug it

Source

pub fn close(&self) -> Result<()>

what drop does, but you get to see whether letting go of what you held and unlocking worked, and you choose the thread that waits for it (up to about 2 seconds when the box doesn’t answer). it works on a shared device too. after it every command fails with Error::Closed and the receivers end, events() gives one that’s already ended, snapshot() still works and medius() gives none. a second close waits for the first one and then says Closed. that’s not the Closed an ended receiver returns

Source§

impl Device

Source

pub fn mock_example_events(&self)

sends every receiver one of each event from Event::examples, through the same queue as real ones, without any of them doing to the device what the real one would. for testing how code reads every kind of event

Source§

impl Device

a device over the medius crate’s mock box, for testing your own code without a box plugged in. it runs the exact code a real Medius gets, only the box is the crate’s model of one, so it proves nothing about hardware and it can only be shaped like a Medius

keep a clone of the MockBox and drive it like a box: push_usages pushes the whole held set (a release is pushing the empty set), push_motion pushes motion, restart() gives Disconnected then Reconnected, and detach(true) and link_lost() give SessionReset. for a drop from the box, take the state from query_catch(), raise its dropped and give it back with with_catch_state, and it shows up as Dropped { Device }. those come on a poller round, so wait with recv_timeout. many mock devices at once on a busy machine can run past the 500 ms command deadline and show a Disconnected that heals on the next round

Source

pub fn mock_medius(mock: MockBox, click_timing: ClickTiming) -> Result<Device>

Source

pub fn mock_medius_manual( mock: MockBox, click_timing: ClickTiming, ) -> Result<(Device, MockPoller)>

the same, but the poller doesn’t run by itself, you tick it with MockPoller::tick

Trait Implementations§

Source§

impl Debug for Device

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Device

§

impl !RefUnwindSafe for Device

§

impl !UnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl UnsafeUnpin for Device

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.