From e7050f9c44af616df965dd4e57116fef39f54ed1 Mon Sep 17 00:00:00 2001 From: Oscar Blue Date: Mon, 7 Oct 2024 21:58:48 +0100 Subject: [PATCH] Added mouse jiggle macro --- .../gmmk/pro/rev1/iso/keymaps/noble/keymap.c | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/keyboards/gmmk/pro/rev1/iso/keymaps/noble/keymap.c b/keyboards/gmmk/pro/rev1/iso/keymaps/noble/keymap.c index c4065bf125..ea6ec1d36e 100644 --- a/keyboards/gmmk/pro/rev1/iso/keymaps/noble/keymap.c +++ b/keyboards/gmmk/pro/rev1/iso/keymaps/noble/keymap.c @@ -16,6 +16,11 @@ along with this program. If not, see . #include QMK_KEYBOARD_H +// mouse jiggler +enum custom_keycodes { + MS_JIGL +}; + // clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -57,7 +62,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), [2] = LAYOUT( - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + MS_JIGL, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DM_REC1, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DM_REC2, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DM_PLY1, @@ -84,6 +89,41 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { [3] = { ENCODER_CCW_CW(KC_TRNS, KC_TRNS) }, }; +bool is_mouse_jiggle_active = false; +bool mouse_jiggle_direction = false; + +uint16_t mouse_jiggle_frequency = 15000; +uint16_t mouse_jiggle_timer = 0; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case MS_JIGL: + if (record->event.pressed) { + is_mouse_jiggle_active = !is_mouse_jiggle_active; + } + break; + } + return true; +}; + +void matrix_scan_user(void) { + if (mouse_jiggle_timer == 0) { + mouse_jiggle_timer = timer_read(); + } + if (is_mouse_jiggle_active) { + if (timer_elapsed(mouse_jiggle_timer) > mouse_jiggle_frequency) { + mouse_jiggle_timer = timer_read(); + if (mouse_jiggle_direction) { + tap_code(KC_MS_LEFT); + } else { + tap_code(KC_MS_RIGHT); + } + mouse_jiggle_direction =! mouse_jiggle_direction; + } + } +}; + + bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { HSV hsv = rgb_matrix_get_hsv(); RGB rgb = hsv_to_rgb(hsv); @@ -93,5 +133,10 @@ bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { } else { RGB_MATRIX_INDICATOR_SET_COLOR(3, 0, 0, 0); } + if (is_mouse_jiggle_active) { + RGB_MATRIX_INDICATOR_SET_COLOR(0, rgb.r, rgb.g, rgb.b); // assuming esc is at led #0 + } else { + RGB_MATRIX_INDICATOR_SET_COLOR(0, 0, 0, 0); + } return false; -} +};