Beginning to adapt Getreuer's Mouse Turbo Click into a mouse jiggler.

This commit is contained in:
2022-02-14 16:06:06 -04:00
parent 1921fc3c9a
commit f2371ed352
4 changed files with 33 additions and 47 deletions
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2022 Google LLC, Copyright 2022 Jay Watson jmwtsn@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -13,19 +13,20 @@
// limitations under the License.
//
//
// For full documentation, see
// Addapted from Pascal Getreuer's Mouse Turbo Click
// For full documentation of Pascal Getreuer's original project, see
// https://getreuer.info/posts/keyboards/mouse-turbo-click
#include "features/mouse_turbo_click.h"
#include "features/mister_smith.h"
// This library relies on that mouse keys and the deferred execution API are
// enabled, which we check for here. Enable them in you rules.mk by setting:
// MOUSEKEY_ENABLE = yes
// DEFERRED_EXEC_ENABLE = yes
#if !defined(MOUSEKEY_ENABLE)
#error "mouse_turbo_click: Please set `MOUSEKEY_ENABLE = yes` in rules.mk."
#error "get_jiggy_withit: Please set `MOUSEKEY_ENABLE = yes` in rules.mk."
#elif !defined(DEFERRED_EXEC_ENABLE)
#error "mouse_turbo_click: Please set `DEFERRED_EXEC_ENABLE = yes` in rules.mk."
#error "get_jiggy_withit: Please set `DEFERRED_EXEC_ENABLE = yes` in rules.mk."
#else
// The click period in milliseconds. For instance a period of 200 ms would be 5
@@ -33,34 +34,34 @@
//
// WARNING: The keyboard might become unresponsive if the period is too small.
// I suggest setting this no smaller than 50.
#define CLICK_PERIOD_MS 80
#define JIGGY_PERIOD 1000
static deferred_token click_token = INVALID_DEFERRED_TOKEN;
static bool click_registered = false;
// Callback used with deferred execution. It alternates between registering and
// unregisting the mouse button.
static uint32_t turbo_click_callback(uint32_t trigger_time, void *cb_arg) {
// Callback used with deferred execution. It alternates between tapping left
// and right mouse keys.
static uint32_t get_jiggy_callback(uint32_t trigger_time, void *cb_arg) {
if (click_registered) {
unregister_code16(KC_MS_BTN1);
tap_code16(KC_MS_L);
click_registered = false;
} else {
click_registered = true;
register_code16(KC_MS_BTN1);
tap_code16(KC_MS_R);
}
return CLICK_PERIOD_MS / 2; // Execute callback again in half a period.
return JIGGY_PERIOD / 2; // Execute callback again in half a period.
}
// Starts Turbo Click, begins the callback.
static void turbo_click_start(void) {
static void get_jiggy_start(void) {
if (click_token == INVALID_DEFERRED_TOKEN) {
uint32_t next_delay_ms = turbo_click_callback(0, NULL);
click_token = defer_exec(next_delay_ms, turbo_click_callback, NULL);
uint32_t next_delay_ms = get_jiggy_callback(0, NULL);
click_token = defer_exec(next_delay_ms, get_jiggy_callback, NULL);
}
}
// Stops Turbo Click, cancels the callback.
static void turbo_click_stop(void) {
static void get_jiggy_stop(void) {
if (click_token != INVALID_DEFERRED_TOKEN) {
cancel_deferred_exec(click_token);
click_token = INVALID_DEFERRED_TOKEN;
@@ -72,13 +73,13 @@ static void turbo_click_stop(void) {
}
}
bool process_mouse_turbo_click(uint16_t keycode, keyrecord_t* record,
uint16_t turbo_click_keycode) {
bool process_get_jiggy_withit(uint16_t keycode, keyrecord_t* record,
uint16_t get_jiggy_keycode) {
static bool locked = false;
static bool tapped = false;
static uint16_t tap_timer = 0;
if (keycode == turbo_click_keycode) {
if (keycode == get_jiggy_keycode) {
if (record->event.pressed) { // Turbo Click key was pressed.
if (tapped && !timer_expired(record->event.time, tap_timer)) {
// If the key was recently tapped, lock turbo click.
@@ -87,17 +88,17 @@ bool process_mouse_turbo_click(uint16_t keycode, keyrecord_t* record,
// Otherwise if currently locked, unlock and stop.
locked = false;
tapped = false;
turbo_click_stop();
get_jiggy_stop();
return false;
}
// Set that the first tap occurred in a potential double tap.
tapped = true;
tap_timer = record->event.time + TAPPING_TERM;
turbo_click_start();
get_jiggy_start();
} else if (!locked) {
// If not currently locked, stop on key release.
turbo_click_stop();
get_jiggy_stop();
}
return false;
@@ -13,7 +13,8 @@
// limitations under the License.
//
//
// Mouse Turbo Click - click the mouse rapidly
// Mouse jiggler - move the mouse once in a while to prevent screen time-out
// Addapted from Pascal Getreuer's Mouse Turbo Click.
//
// This library implements a "Turbo Click" button that clicks the mouse rapidly,
// implemented using mouse keys and a periodic callback function:
@@ -28,7 +29,7 @@
// MOUSEKEY_ENABLE = yes, DEFERRED_EXEC_ENABLE = yes.
//
//
// For full documentation, see
// For full documentation of Pascal Getreuer's original project, see
// https://getreuer.info/posts/keyboards/mouse-turbo-click
#pragma once
@@ -48,5 +49,5 @@
//
// return true;
// }
bool process_mouse_turbo_click(uint16_t keycode, keyrecord_t* record,
uint16_t turbo_click_keycode);
bool process_get_jiggy_withit(uint16_t keycode, keyrecord_t* record,
uint16_t get_jiggy_keycode);
+4 -19
View File
@@ -16,7 +16,7 @@
*/
#include QMK_KEYBOARD_H
#include "features/mouse_turbo_click.h"
#include "features/mister_smith.h"
enum custom_keycodes {
MSG = SAFE_RANGE,
@@ -29,32 +29,17 @@ enum custom_keycodes {
NIS,
SELNUM,
DISCO,
TURBO,
NOCON,
SLSAST,
ASTSLS,
NXT,
JIGGY1,
JIGGY2
JIGGY
};
/* Code for getreuer mouse_turbo_click
bool process_record_user(uint16_t keycode, keyrecord_t* record) {
// Your macros ...
return true;
}
*/
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!process_mouse_turbo_click(keycode, record, TURBO)) { return false; }
if (!process_get_jiggy_withit(keycode, record, JIGGY)) { return false; }
switch (keycode) {
@@ -242,7 +227,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[1] = LAYOUT( /*Numpad*/
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LNUM, KC_DEL,
_______, TURBO, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, KC_P0, _______, SLSAST, ASTSLS, _______, KC_VOLU,
_______, JIGGY, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, KC_P0, _______, SLSAST, ASTSLS, _______, KC_VOLU,
_______, _______, _______, DISCO, NOCON, _______, KC_P4, KC_P5, KC_P6, _______, _______, _______, _______, KC_VOLD,
_______, _______, _______, NXT, _______, _______, KC_P1, KC_P2, KC_P3, _______, _______, _______, KC_PGUP, MU_TOG,
_______, _______, _______, _______, KC_P0, _______, KC_HOME, KC_PGDN, KC_END),
+1 -2
View File
@@ -1,4 +1,3 @@
SRC += features/mouse_turbo_click.c
SRC += features/mister_smith.c
MOUSEKEY_ENABLE = yes
DEFERRED_EXEC_ENABLE = yes