2 Copyright 2013 Jun Wako <wakojun@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef ACTION_MACRO_H
18 #define ACTION_MACRO_H
24 #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
25 #define MACRO_GET(p) pgm_read_byte(p)
27 typedef uint8_t macro_t;
30 #ifndef NO_ACTION_MACRO
31 void action_macro_play(const macro_t *macro_p);
33 #define action_macro_play(macro)
39 * code(0x04-73) // key down(1byte)
40 * code(0x04-73) | 0x80 // key up(1byte)
41 * { KEY_DOWN, code(0x04-0xff) } // key down(2bytes)
42 * { KEY_UP, code(0x04-0xff) } // key up(2bytes)
43 * WAIT // wait milli-seconds
44 * INTERVAL // set interval between macro commands
45 * END // stop macro execution
47 * Ideas(Not implemented):
56 enum macro_command_id{
62 /* 0x04 - 0x73 (reserved for keycode down) */
71 /* 0x84 - 0xf3 (reserved for keycode up) */
77 /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
78 * if keycode between 0x04 and 0x73
79 * keycode / (keycode|0x80)
81 * {KEY_DOWN, keycode} / {KEY_UP, keycode}
83 #define DOWN(key) KEY_DOWN, (key)
84 #define UP(key) KEY_UP, (key)
85 #define TYPE(key) DOWN(key), UP(key)
86 #define WAIT(ms) WAIT, (ms)
87 #define INTERVAL(ms) INTERVAL, (ms)
88 #define STORE() MOD_STORE
89 #define RESTORE() MOD_RESTORE
90 #define CLEAR() MOD_CLEAR
93 #define D(key) DOWN(KC_##key)
95 #define U(key) UP(KC_##key)
97 #define T(key) TYPE(KC_##key)
99 #define W(ms) WAIT(ms)
101 #define I(ms) INTERVAL(ms)
102 /* store modifier(s) */
104 /* restore modifier(s) */
105 #define RM() RESTORE()
106 /* clear modifier(s) */
109 #define ST(key) D(LSFT), T(key), U(LSFT)
110 /* modifier utility macros */
111 /* Example: Ctrl+Alt+[Shift+]<key1,key2> is CTL_( ALT_( [S]T(key1), [S]T(key2) )) . */
112 #define SFT_(...) D(LSFT), __VA_ARGS__, U(LSFT)
113 #define CTL_(...) D(LCTL), __VA_ARGS__, U(LCTL)
114 #define ALT_(...) D(LALT), __VA_ARGS__, U(LALT)
115 #define AGR_(...) D(RALT), __VA_ARGS__, U(RALT)
116 /* Unicode macros for XOrg/MacOs/Win. */
117 /* Example: UNIW_(0,1,4,9) enters a bullet glyph on Windows using Alt+KeyPad(####). */
118 #define UNIX_(d1,d2,d3,d4) CTL_(ST(U)), T(d1), T(d2), T(d3), T(d4) , T(ENT)
119 #define UNIM_(d1,d2,d3,d4) ALT_( T(d1), T(d2), T(d3), T(d4) )
120 #define UNIW_(d1,d2,d3,d4) ALT_( T(P##d1), T(P##d2), T(P##d3), T(P##d4) )
122 /* for backward comaptibility */
123 #define MD(key) DOWN(KC_##key)
124 #define MU(key) UP(KC_##key)
127 #endif /* ACTION_MACRO_H */