hakbraley

QMK Spam Macro2

Sep 8th, 2021 (edited)
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/pkdv7t/repeat_macro_on_loop/
  2.     Code to spam alternating between Mouse1 and Enter every so often, with a macro to toggle it.
  3.    
  4.     Make sure you have 'MOUSEKEY_ENABLE = yes' in your rules.mk file.
  5.  */
  6.  
  7. enum custom_keycodes {
  8.     M1_ENTR = SAFE_RANGE,  //name your macro. always start the list at SAFE_RANGE
  9.     //other macros,
  10. };
  11.  
  12. #define M1_ENTR_DELAY 200     //configure time to wait between macro executions, in milliseconds
  13. bool M1_ENTR_active = false;  //boolean to track if macro is active
  14. uint16_t M1_ENTR_timer = 0;   //timer to track the last time macro was executed
  15. uint8_t M1_ENTR_key = 0;      //next key to tap, alternate between mouse1(0) and enter(1)
  16.  
  17. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  18.     switch (keycode) {
  19.         case M1_ENTR:
  20.             if (record->event.pressed) {            //if M1_ENTR is pressed
  21.                 M1_ENTR_active = !M1_ENTR_active;   //  flip the boolean to turn macro on or off
  22.             }
  23.             break;
  24.         //case other_macros:
  25.             //...
  26.     }
  27.     return true;
  28. }
  29.  
  30.  
  31. void matrix_scan_user(void) {  //runs after every matrix scan
  32.     if (M1_ENTR_active) {                                    //if macro is active
  33.         if (timer_elapsed(M1_ENTR_timer) > M1_ENTR_DELAY) {  //and it has been longer than M1_ENTR_DELAY
  34.             M1_ENTR_timer = timer_read();                    //  reset timer to the current time
  35.             if (M1_ENTR_key == 0) {                          //  if key is 0(mouse1)
  36.                 tap_code16(KC_MS_BTN1);                      //    tap mouse button 1
  37.                 M1_ENTR_key = 1;                             //    set next key to 1(enter)
  38.             } else if (M1_ENTR_key == 1) {                   //  else if key is 1(enter)
  39.                 tap_code16(KC_ENTER);                        //    tap enter
  40.                 M1_ENTR_key = 0;                             //    set next key to 0(mouse1)
  41.             }
  42.         }
  43.     }
  44. }
  45.  
Add Comment
Please, Sign In to add comment