Actions
Actions are the behaviors that run in response to key events (i.e., key presses and key releases).
At the type level, an action is defined by implementing the Action trait. The Action trait has two required methods: on_press and on_release, which define an action's behavior when a key is pressed or released, respectively.
Action Types
No-Op
The NoOp action does nothing when executed. It can be used for keys that should not perform any action.
Key code
A key code can be sent using the Key type.
Key::ALayer
The Layer action switches to a specified layer while the key is held and switches back to the previous layer when the key is released.
Layer::new(LayerId(1))Per-Layer
The PerLayer action wraps multiple other actions with a corresponding layer ID and executes one of them based on the currently active layer.
// Sends the key code "A" when layer 0 is active and the key code "B" when
// layer 1 is active
PerLayer::new((Key::A, Key::B), [LayerId(0), LayerId(1)].into())Hold-Tap
The HoldTap action executes one action when the key is tapped and another action when the key is held.
// Sends Left Control when the key is held for at least 100 milliseconds,
// otherwise sends Space
HoldTap::new(Key::LCtrl, Key::Space)
.tapping_term(Duration::from_millis(100)) // optional, defaults to 200msToggle
The Toggle action wraps another action and toggles its state on each key press. The wrapped action's on_press method will be executed when the key is pressed, and the on_release method will be executed when the key is pressed again.
Toggle::new(Key::A)Sticky
The Sticky action wraps another action and effectively holds it down until another key code is sent or a certain time has elapsed.
// Sends Left Control and holds it until a non-modifier key code is sent or 2 seconds have elapsed.
Sticky::new(Key::LCtrl)
.timeout(Duration::from_secs(2)) // optional, defaults to 1 second
.ignore_modifiers(true) // optional, defaults to trueOrdered
The Ordered action activates multiple other actions in the order they are listed. On key press, it calls each child's on_press in order. On release, it calls each child's on_release in reverse order.
// Presses "A", "B" and "C" in order, then releases them in reverse order
Ordered::new((Key::A, Key::B, Key::C))Unordered
The Unordered action executes multiple other actions concurrently without an explicit order.
// Sends the key code "A" and switches to layer 1
Unordered::new((Key::A, Layer::new(LayerId(1))))