Lock
A scale sets how much of one native input reaches the game PC. Injection still drives that input unweighed.
scale -100 native <-- inverted scale 0 native --X blocked scale 40 native -.-> 40% gets through scale 100 native --> untouched scale 200 native ==> doubled injected always --> unweighed, whatever the scale
| Weigh a... | Signed percent | Block | Release |
|---|---|---|---|
| relative axis (X / Y / wheel / pan) | scale / scale_axis | lock / lock_axis | unlock / unlock_axis |
| button, key, or media usage | truncates to a lock; a negative is refused | lock | unlock |
| a whole class (blanket) | scale_all | lock_all | unlock_all |
All are fire-and-forget: one frame, no reply. query_locks reads the active set.
scaleKeep a percentage of a native input
fn scale(&self, target: impl Into<LockTarget>, direction: Direction, scale: i16) -> Result<()>
Fire-and-forget
| Parameter | Type | Description |
|---|---|---|
target | impl Into<LockTarget> | An Axis (X, Y, wheel, or pan) or any Usage (button, key, or media). |
direction | Direction | A fixed sign or edge, or With / Against relative to the bearing. A relative direction on anything but an axis returns Error::RelativeDirection. Media has no edges, so an edge on it is sent as Both. |
scale | i16 | Percent of the native value kept. LOCK_SCALE_BLOCK (0) blocks and LOCK_SCALE_PASS (100) passes untouched. Above 100 amplifies, up to LOCK_SCALE_MAX (255). Below 0 reverses, down to LOCK_SCALE_MIN (-255). Outside that range returns Error::LockScaleRange. |
A delta is weighed by one fixed-direction scale times one relative scale, so a block in either zeroes it. With and Against need a live bearing (set_bearing). A momentary usage is one bit: any scale <100 locks it, and a negative returns Error::LockScaleUsage.
The delta's sign before weighing picks which direction's scale applies: Positive at -100 turns rightward motion leftward and leaves leftward motion alone.
Direction::Both writes the scale to the two fixed signs and a full pass to the relative pair, so Both of 50 means 50% whether or not a bearing is live.
use medius::{Device, Axis, Direction};
let device = Device::find()?;
device.scale(Axis::X, Direction::Against, 40)?; // 40% of native motion opposing the injection
device.scale(Axis::X, Direction::With, 130)?; // 130% of it along the injection
device.scale(Axis::Y, Direction::Negative, 60)?; // 60% of upward motion, always
device.scale(Axis::Y, Direction::Both, -100)?; // Y invertedlockBlock a native input
fn lock(&self, target: impl Into<LockTarget>, direction: Direction) -> Result<()>
Fire-and-forget
scale at LOCK_SCALE_BLOCK. On a usage, Positive and Negative are also spelled Direction::PRESS and Direction::RELEASE.
| Parameter | Type | Description |
|---|---|---|
target | impl Into<LockTarget> | An Axis (X, Y, wheel, or pan) or any Usage (button, key, or media). |
direction | Direction | Which sign or edge to block. An axis also takes the bearing-relative With / Against. |
A lock holds until unlock, control-PC silence, reset, inter-chip link loss, or the real device detaching. The wire layout is on the native LOCK command.
use medius::{Device, Axis, Button, Key, MediaKey, Direction};
let device = Device::find()?;
device.lock(Axis::X, Direction::Both)?; // block horizontal motion
device.lock(Button::LEFT, Direction::Positive)?; // block left-click press
device.lock(Key::LEFT_GUI, Direction::Both)?; // block the GUI/Windows key
device.lock(MediaKey::PLAY_PAUSE, Direction::Both)?; // media has no edges
device.move_rel(50, 0)?; // injection still moves XunlockClear a block
fn unlock(&self, target: impl Into<LockTarget>, direction: Direction) -> Result<()>
Fire-and-forget
scale at LOCK_SCALE_PASS for the same target and direction. Direction::Both clears every direction of the target, the bearing-relative pair included.
use medius::{Device, Axis, Direction};
let device = Device::find()?;
device.unlock(Axis::X, Direction::Both)?; // X passes untouched againlock_axis / unlock_axis / scale_axis Weigh a relative axis by sign
fn lock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
fn unlock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
fn scale_axis(&self, axis: Axis, direction: Direction, scale: i16) -> Result<()>
Fire-and-forget
lock / unlock / scale for an Axis, with a sign as the direction.
use medius::{Device, Axis, Direction};
let device = Device::find()?;
device.lock_axis(Axis::Wheel, Direction::Positive)?; // block scroll up, keep scroll down
device.unlock_axis(Axis::Wheel, Direction::Positive)?;lock_all / unlock_all / scale_all Weigh a whole class at once
fn lock_all(&self, what: Blanket, direction: Direction) -> Result<()>
fn unlock_all(&self, what: Blanket, direction: Direction) -> Result<()>
fn scale_all(&self, what: Blanket, direction: Direction, scale: i16) -> Result<()>
Fire-and-forget
A Blanket weighs a whole input group. direction applies to every member as it would to one. Keys takes an edge; Media has no edges, so it sends Both.
Blanket::Aim addresses X and Y together in BearingMode::Vector, which reads X and Y as one vector.
use medius::{Device, Blanket, Direction};
let device = Device::find()?;
device.lock_all(Blanket::Keys, Direction::Both)?; // every key, both edges
device.lock_all(Blanket::Keys, Direction::Positive)?; // press edges only: a held key still releases
device.unlock_all(Blanket::Keys, Direction::Both)?;
device.scale_all(Blanket::Aim, Direction::Against, 40)?; // 40% of motion opposing the injection, X and YOn AsyncDevice locks fire, query_locks awaits
AsyncDevice keeps every lock call synchronous, with no reply to await: scale, lock/unlock, scale_axis, and scale_all with their lock and unlock pairs. query_locks is a future.
use futures::executor::block_on;
use medius::{AsyncDevice, Axis, Direction};
let device = AsyncDevice::open("/dev/ttyACM0")?;
device.lock(Axis::Y, Direction::Both)?; // sync, no await
let locks = block_on(device.query_locks())?; // query awaits