Add in basic documentation for Macro system
This commit is contained in:
parent
a88ad58342
commit
a6a6d4ab49
@ -379,19 +379,33 @@ Default Layer also has bitwise operations, they are executed when key is release
|
|||||||
ACTION_DEFAULT_LAYER_BIT_SET(part, bits)
|
ACTION_DEFAULT_LAYER_BIT_SET(part, bits)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 2.3 Macro action
|
### 2.3 Macro action
|
||||||
***TBD***
|
`Macro` actions allow you to register a complex sequence of keystrokes when a key is pressed, where macros are simple sequences of keypresses.
|
||||||
|
|
||||||
`Macro` action indicates complex key strokes.
|
ACTION_MACRO(id)
|
||||||
|
ACTION_MACRO_TAP(id)
|
||||||
|
|
||||||
MACRO( D(LSHIFT), D(D), END )
|
`id` is an 8-bit user-defined value the macro getter function can use to pick the specific macro.
|
||||||
MACRO( U(D), U(LSHIFT), END )
|
|
||||||
MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END )
|
|
||||||
|
|
||||||
#### 2.3.1 Macro Commands
|
|
||||||
- **MACRO()**
|
#### 2.3.1 Implementing Macro getter function
|
||||||
- **MACRO_NONE**
|
To implement `macro` functions, the macro lookup list must be implemented:
|
||||||
|
|
||||||
|
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
|
||||||
|
|
||||||
|
The function must always return a valid macro, and default implementation of `action_get_macro` always returns `MACRO_NONE` which has no effect.
|
||||||
|
|
||||||
|
#### 2.3.1.1 Limitations
|
||||||
|
Similar to the Function Action system, the selector functions is passed a `keyrecord_t` object, so it can inspect the key state (e.g. different macros on key press or release), and key itself.
|
||||||
|
|
||||||
|
Unlike the Function Action system,`macros` are pre-recorded key sequences, so you can only select from a list. If you want to use dynamic macros then you should look at the more complex function action system.
|
||||||
|
|
||||||
|
#### 2.3.2 Implementing/Defining Macro sequences
|
||||||
|
Macros are of the form (must be wrapped by the `MACRO` function, and end with an `END` mark)
|
||||||
|
|
||||||
|
MACRO( ..., END )
|
||||||
|
|
||||||
|
Within each macro, the following commands can be used:
|
||||||
|
|
||||||
- **I()** change interval of stroke.
|
- **I()** change interval of stroke.
|
||||||
- **D()** press key
|
- **D()** press key
|
||||||
@ -401,19 +415,25 @@ Default Layer also has bitwise operations, they are executed when key is release
|
|||||||
- **SM()** store modifier state
|
- **SM()** store modifier state
|
||||||
- **RM()** restore modifier state
|
- **RM()** restore modifier state
|
||||||
- **CM()** clear modifier state
|
- **CM()** clear modifier state
|
||||||
- **END** end mark
|
|
||||||
|
e.g.:
|
||||||
|
|
||||||
|
MACRO( D(LSHIFT), D(D), END ) // hold down LSHIFT and D - will print 'D'
|
||||||
|
MACRO( U(D), U(LSHIFT), END ) // release U and LSHIFT keys (an event.pressed == False counterpart for the one above)
|
||||||
|
MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) // slowly print out h-e-l-l---o
|
||||||
|
|
||||||
#### 2.3.2 Examples
|
#### 2.3.2 Examples
|
||||||
***TBD***
|
|
||||||
|
in keymap.c, define `action_get_macro`
|
||||||
|
|
||||||
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
{
|
{
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case HELLO:
|
case 0:
|
||||||
return (record->event.pressed ?
|
return (record->event.pressed ?
|
||||||
MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
|
MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
|
||||||
MACRO_NONE );
|
MACRO_NONE );
|
||||||
case ALT_TAB:
|
case 1:
|
||||||
return (record->event.pressed ?
|
return (record->event.pressed ?
|
||||||
MACRO( D(LALT), D(TAB), END ) :
|
MACRO( D(LALT), D(TAB), END ) :
|
||||||
MACRO( U(TAB), END ));
|
MACRO( U(TAB), END ));
|
||||||
@ -421,7 +441,12 @@ Default Layer also has bitwise operations, they are executed when key is release
|
|||||||
return MACRO_NONE;
|
return MACRO_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in keymap.c, bind items in `fn_actions` to the macro function
|
||||||
|
|
||||||
|
const action_t PROGMEM fn_actions[] = {
|
||||||
|
[0] = ACTION_MACRO(0), // will print 'hello' for example
|
||||||
|
[1] = ACTION_MACRO(1),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
### 2.4 Function action
|
### 2.4 Function action
|
||||||
|
Loading…
Reference in New Issue
Block a user