Skip to main content

HidUsage

Struct HidUsage 

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

Decoded ZMK HID usage values used in typed behavior APIs. Lossless decoded ZMK HID usage value (base usage + modifiers).

Implementations§

Source§

impl HidUsage

Source

pub fn from_encoded(encoded: u32) -> Self

Decode from ZMK’s encoded usage format.

ZMK encodes as:

  • bits 31:24: modifiers
  • bits 23:16: usage page
  • bits 15:00: usage id

If page is 0, ZMK treats it as keyboard page (0x07).

Examples found in repository?
examples/basic_example.rs (line 111)
66fn run_example<T: Read + Write>(mut client: StudioClient<T>) -> Result<(), Box<dyn Error>> {
67    let info = client.get_device_info()?;
68    println!("Device: {}", info.name);
69    println!("Lock: {:?}", client.get_lock_state()?);
70
71    let behavior_ids = client.list_all_behaviors()?;
72    println!("Behavior count: {}", behavior_ids.len());
73    if let Some(first_behavior_id) = behavior_ids.first().copied() {
74        let details = client.get_behavior_details(first_behavior_id)?;
75        println!("First behavior: {} ({})", details.id, details.display_name);
76    }
77
78    let keymap = match client.get_keymap() {
79        Ok(keymap) => keymap,
80        Err(ClientError::Meta(_)) => {
81            println!("Keymap request denied (likely locked); press `&studio_unlock` then rerun.");
82            return Ok(());
83        }
84        Err(err) => return Err(Box::new(err)),
85    };
86    println!("Layers: {}", keymap.layers.len());
87
88    let layouts = client.get_physical_layouts()?;
89    println!(
90        "Physical layouts: {} (active index: {})",
91        layouts.layouts.len(),
92        layouts.active_layout_index
93    );
94
95    let Some(first_layer) = keymap.layers.first() else {
96        return Ok(());
97    };
98    if first_layer.bindings.is_empty() {
99        return Ok(());
100    }
101
102    let layer_id = first_layer.id;
103    let key_position = 0;
104
105    let before = client.get_key_at(layer_id, key_position)?;
106    println!("Before: {before:?}");
107
108    client.set_key_at(
109        layer_id,
110        key_position,
111        Behavior::KeyPress(HidUsage::from_encoded(Keycode::A.to_hid_usage())),
112    )?;
113    let after = client.get_key_at(layer_id, key_position)?;
114    println!("After:  {after:?}");
115
116    // Change management APIs.
117    let has_changes = client.check_unsaved_changes()?;
118    println!("Unsaved changes: {has_changes}");
119    if has_changes {
120        client.discard_changes()?;
121    }
122
123    Ok(())
124}
Source

pub fn from_parts(page: u16, id: u16, modifiers: u8) -> Self

Source

pub fn to_hid_usage(self) -> u32

Source

pub fn page(self) -> u16

Source

pub fn id(self) -> u16

Source

pub fn modifiers(self) -> u8

Source

pub fn base(self) -> Self

Source

pub fn known_keycode(self) -> Option<Keycode>

Source

pub fn known_base_keycode(self) -> Option<Keycode>

Source

pub fn modifier_labels(self) -> Vec<&'static str>

Trait Implementations§

Source§

impl Clone for HidUsage

Source§

fn clone(&self) -> HidUsage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HidUsage

Source§

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

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

impl Display for HidUsage

Source§

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

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

impl Hash for HidUsage

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HidUsage

Source§

fn eq(&self, other: &HidUsage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for HidUsage

Source§

impl Eq for HidUsage

Source§

impl StructuralPartialEq for HidUsage

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.