Advertisement
hakbraley

LOWER_CLICK QMK CODE

Aug 18th, 2021 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #define LOWCLK_HOLD_LIMIT 400  //configure hold time for LOWER_CLICK. hold for less than 400ms to left click
  2.  
  3. enum custom_keycodes {
  4.     MACRO1 = SAFE_RANGE,  //start of other macro keys
  5.     MACRO2,
  6.     MACRO3,
  7.     LOWER_CLICK           //custom macro keycode, name it what you want
  8. };
  9.  
  10. uint16_t lowclk_hold_timer = 0;  //lower_click timer variable
  11.  
  12. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  13.     switch (keycode) {
  14.         //other macros
  15.         case BACKLIT:
  16.             //...
  17.             break;
  18.         case LOWER_CLICK:
  19.             if (record->event.pressed) {           //when LOWER_CLICK is pressed
  20.                 lowclk_hold_timer = timer_read();  //  mark the time it was pressed
  21.                 layer_on(_LOWER);                  //  go to _LOWER layer
  22.             } else {                               //when LOWER_CLICK is released
  23.                 layer_off(_LOWER);                 //  leave _LOWER layer
  24.                 if (timer_elapsed(lowclk_hold_timer) < LOWCLK_HOLD_LIMIT)
  25.                     tap_code16(KC_MS_BTN1);        //  left click if macro key was held for less than LOWCLK_HOLD_LIMIT ms
  26.             }
  27.             break;
  28.     }
  29.     return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement