hakbraley

QMK Spam Macro

Sep 8th, 2021 (edited)
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/pkdv7t/repeat_macro_on_loop/
  2.     Code to spam 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.  
  16. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  17.     switch (keycode) {
  18.         case M1_ENTR:
  19.             if (record->event.pressed) {            //if M1_ENTR is pressed
  20.                 M1_ENTR_active = !M1_ENTR_active;   //  flip the boolean to turn macro on or off
  21.             }
  22.             break;
  23.         //case other_macros:
  24.             //...
  25.     }
  26.     return true;
  27. }
  28.  
  29.  
  30. void matrix_scan_user(void) {  //runs after every matrix scan
  31.     if (M1_ENTR_active) {                                    //if macro is active
  32.         if (timer_elapsed(M1_ENTR_timer) > M1_ENTR_DELAY) {  //and it has been longer than M1_ENTR_DELAY
  33.             M1_ENTR_timer = timer_read();                    //  reset timer to the current time
  34.             tap_code16(KC_MS_BTN1);                          //  tap mouse button 1
  35.             tap_code16(KC_ENTER);                            //  tap enter
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment