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