Added mouse jiggle macro

This commit is contained in:
Oscar Blue 2024-10-07 21:58:48 +01:00
parent 8443b2b120
commit e7050f9c44

View file

@ -16,6 +16,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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;
}
};