Skip to content

Commit e80f3c1

Browse files
committed
Add in basic documentation for Macro system
1 parent 35e8a76 commit e80f3c1

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

doc/keymap.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,33 @@ Default Layer also has bitwise operations, they are executed when key is release
379379
ACTION_DEFAULT_LAYER_BIT_SET(part, bits)
380380
381381
382-
383382
### 2.3 Macro action
384-
***TBD***
383+
`Macro` actions allow you to register a complex sequence of keystrokes when a key is pressed, where macros are simple sequences of keypresses.
384+
385+
ACTION_MACRO(id)
386+
ACTION_MACRO_TAP(id)
387+
388+
`id` is an 8-bit user-defined value the macro getter function can use to pick the specific macro.
389+
390+
391+
#### 2.3.1 Implementing Macro getter function
392+
To implement `macro` functions, the macro lookup list must be implemented:
393+
394+
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
395+
396+
The function must always return a valid macro, and default implementation of `action_get_macro` always returns `MACRO_NONE` which has no effect.
397+
398+
#### 2.3.1.1 Limitations
399+
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.
400+
401+
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.
385402
386-
`Macro` action indicates complex key strokes.
387-
388-
MACRO( D(LSHIFT), D(D), END )
389-
MACRO( U(D), U(LSHIFT), END )
390-
MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END )
403+
#### 2.3.2 Implementing/Defining Macro sequences
404+
Macros are of the form (must be wrapped by the `MACRO` function, and end with an `END` mark)
391405
392-
#### 2.3.1 Macro Commands
393-
- **MACRO()**
394-
- **MACRO_NONE**
406+
MACRO( ..., END )
407+
408+
Within each macro, the following commands can be used:
395409
396410
- **I()** change interval of stroke.
397411
- **D()** press key
@@ -401,27 +415,38 @@ Default Layer also has bitwise operations, they are executed when key is release
401415
- **SM()** store modifier state
402416
- **RM()** restore modifier state
403417
- **CM()** clear modifier state
404-
- **END** end mark
418+
419+
e.g.:
420+
421+
MACRO( D(LSHIFT), D(D), END ) // hold down LSHIFT and D - will print 'D'
422+
MACRO( U(D), U(LSHIFT), END ) // release U and LSHIFT keys (an event.pressed == False counterpart for the one above)
423+
MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) // slowly print out h-e-l-l---o
405424
406425
#### 2.3.2 Examples
407-
***TBD***
426+
427+
in keymap.c, define `action_get_macro`
408428
409429
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
410430
{
411431
switch (id) {
412-
case HELLO:
432+
case 0:
413433
return (record->event.pressed ?
414434
MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
415435
MACRO_NONE );
416-
case ALT_TAB:
436+
case 1:
417437
return (record->event.pressed ?
418438
MACRO( D(LALT), D(TAB), END ) :
419439
MACRO( U(TAB), END ));
420440
}
421441
return MACRO_NONE;
422442
}
423443
424-
444+
in keymap.c, bind items in `fn_actions` to the macro function
445+
446+
const action_t PROGMEM fn_actions[] = {
447+
[0] = ACTION_MACRO(0), // will print 'hello' for example
448+
[1] = ACTION_MACRO(1),
449+
};
425450
426451
427452
### 2.4 Function action

0 commit comments

Comments
 (0)