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
impl Device
Sourcepub fn snapshot(&self) -> Arc<Snapshot> ⓘ
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
Sourcepub fn move_by(&self, dx: i16, dy: i16) -> Result<()>
pub fn move_by(&self, dx: i16, dy: i16) -> Result<()>
moves by counts, going through whatever smoothing the box has on
Sourcepub fn move_now(&self, dx: i16, dy: i16) -> Result<()>
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
pub fn press(&self, button: Button) -> Result<()>
pub fn release(&self, button: Button) -> Result<()>
Sourcepub fn click(&self, button: Button) -> Result<()>
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
pub fn click_with(&self, button: Button, click: Click) -> Result<()>
pub fn release_key(&self, key: Key) -> Result<()>
Sourcepub fn tap_key(&self, key: Key) -> Result<()>
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
pub fn tap_key_with(&self, key: Key, tap: Click) -> Result<()>
Sourcepub fn press_media(&self, key: MediaKey) -> Result<()>
pub fn press_media(&self, key: MediaKey) -> Result<()>
holds a media key down until release_media
pub fn release_media(&self, key: MediaKey) -> Result<()>
pub fn tap_media(&self, key: MediaKey) -> Result<()>
pub fn tap_media_with(&self, key: MediaKey, tap: Click) -> 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
Sourcepub fn lock_key(&self, key: Key) -> Result<()>
pub fn lock_key(&self, key: Key) -> Result<()>
keeps the physical key from reaching the PC until unlock_key
pub fn unlock_key(&self, key: Key) -> Result<()>
Sourcepub fn lock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
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
Sourcepub fn unlock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
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
Sourcepub fn scale_axis(
&self,
axis: Axis,
direction: Direction,
percent: i16,
) -> Result<()>
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
pub fn wheel(&self, notches: i16) -> Result<()>
Sourcepub fn discard_pending_moves(&self) -> Result<()>
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
Sourcepub fn events(&self) -> Events ⓘ
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
Sourcepub fn events_of(&self, kinds: EventKinds) -> Events ⓘ
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
Sourcepub fn medius(&self) -> Option<Device>
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
Sourcepub fn close(&self) -> Result<()>
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
impl Device
Sourcepub fn mock_example_events(&self)
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
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
pub fn mock_medius(mock: MockBox, click_timing: ClickTiming) -> Result<Device>
Sourcepub fn mock_medius_manual(
mock: MockBox,
click_timing: ClickTiming,
) -> Result<(Device, MockPoller)>
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