Expand description
“Composite” keys; an aggregate type used for a common context and event.
This module implements the keymap::Key
for a ‘composite’ key,
which can be any of the other key definitions,
and is the default Key for the keymap::KeyMap
implementation.
§Keyboard variant
§JSON
use smart_keymap::key;
use key::{composite, keyboard};
type Ctx = composite::Context;
type Key = composite::BaseKey;
let json = r#"
{ "key_code": 4 }
"#;
let expected_key: Key = Key::Keyboard(keyboard::Key::new(0x04));
let actual_key: Key = serde_json::from_str(json).unwrap();
assert_eq!(expected_key, actual_key);
§TapHold variant
§JSON
use smart_keymap::key;
use key::{composite, keyboard, layered, tap_hold};
type Ctx = composite::Context;
type Key = composite::TapHoldKey<composite::BaseKey>;
let json = r#"
{ "hold": { "key_code": 224 }, "tap": { "key_code": 4 } }
"#;
let expected_key: Key = Key::tap_hold(tap_hold::Key {
tap: keyboard::Key::new(4).into(),
hold: keyboard::Key::new(224).into(),
});
let actual_key: Key = serde_json::from_str(json).unwrap();
assert_eq!(expected_key, actual_key);
§Layer Modifier Key variant
§JSON
use smart_keymap::key;
use key::{composite, layered};
type Ctx = composite::Context;
type Key = composite::BaseKey;
let json = r#"
{ "Hold": 2 }
"#;
let expected_key: Key = Key::LayerModifier(layered::ModifierKey::Hold(2));
let actual_key: Key = serde_json::from_str(json).unwrap();
assert_eq!(expected_key, actual_key);
§Layered Key variant
§JSON
use smart_keymap::key;
use key::{composite, keyboard, layered};
type Ctx = composite::Context;
type Key = composite::LayeredKey<composite::TapHoldKey<composite::BaseKey>>;
let json = r#"
{
"base": { "key_code": 4 },
"layered": [{ "key_code": 5 }, null, { "key_code": 7 }]
}
"#;
let expected_key: Key = Key::layered(layered::LayeredKey::new(
keyboard::Key::new(0x04).into(),
[Some(keyboard::Key::new(0x05).into()), None, Some(keyboard::Key::new(0x07).into())],
));
let actual_key: Key = serde_json::from_str(json).unwrap();
assert_eq!(expected_key, actual_key);
Structs§
- Chorded
- Newtype for ChordedNestable keys so they can implement key::Key.
- Config
- Config used for constructing initial context
- Context
- An aggregate context for key::Contexts.
- Layered
- Newtype for LayeredNestable keys so they can implement key::Key.
- TapHold
- Newtype for TapHoldNestable keys so they can implement key::Key.
Enums§
- BaseKey
- An aggregate of key::Key types.
- Chorded
Key - An aggregate of key::Key types.
- Event
- Sum type aggregating the key::Event types.
- KeyState
- Aggregate enum for key state. (i.e. pressed key data).
- Layered
Key - An aggregate of key::Key types.
- Pending
KeyState - Aggregate enum for key state. (i.e. pressed key data).
- TapHold
Key - An aggregate of key::Key types.
Constants§
- DEFAULT_
CONFIG - The default config.
- DEFAULT_
CONTEXT - The default context.
Traits§
- Chorded
Nestable - Trait for types which can be nested in ChordedKey variants.
- Layered
Nestable - Trait for types which can be nested in LayeredKey variants.
- TapHold
Nestable - Trait for types which can be nested in TapHoldKey variants.
Type Aliases§
- Key
- Type alias for composite key types.
- Pressed
KeyResult - Type alias for result from new_pressed_key.