Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/pkdv7t/repeat_macro_on_loop/
- Code to spam alternating between Mouse1 and Enter every so often, with a macro to toggle it.
- Make sure you have 'MOUSEKEY_ENABLE = yes' in your rules.mk file.
- */
- enum custom_keycodes {
- M1_ENTR = SAFE_RANGE, //name your macro. always start the list at SAFE_RANGE
- //other macros,
- };
- #define M1_ENTR_DELAY 200 //configure time to wait between macro executions, in milliseconds
- bool M1_ENTR_active = false; //boolean to track if macro is active
- uint16_t M1_ENTR_timer = 0; //timer to track the last time macro was executed
- uint8_t M1_ENTR_key = 0; //next key to tap, alternate between mouse1(0) and enter(1)
- bool process_record_user(uint16_t keycode, keyrecord_t *record) {
- switch (keycode) {
- case M1_ENTR:
- if (record->event.pressed) { //if M1_ENTR is pressed
- M1_ENTR_active = !M1_ENTR_active; // flip the boolean to turn macro on or off
- }
- break;
- //case other_macros:
- //...
- }
- return true;
- }
- void matrix_scan_user(void) { //runs after every matrix scan
- if (M1_ENTR_active) { //if macro is active
- if (timer_elapsed(M1_ENTR_timer) > M1_ENTR_DELAY) { //and it has been longer than M1_ENTR_DELAY
- M1_ENTR_timer = timer_read(); // reset timer to the current time
- if (M1_ENTR_key == 0) { // if key is 0(mouse1)
- tap_code16(KC_MS_BTN1); // tap mouse button 1
- M1_ENTR_key = 1; // set next key to 1(enter)
- } else if (M1_ENTR_key == 1) { // else if key is 1(enter)
- tap_code16(KC_ENTER); // tap enter
- M1_ENTR_key = 0; // set next key to 0(mouse1)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment