Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mousekeys: Make KC_ACL_* behavior configurable even when the constant-speed-mode is turned off #6062

Closed
wants to merge 12 commits into from
Closed
71 changes: 23 additions & 48 deletions docs/feature_mouse_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,9 @@ In your keymap you can use the following keycodes to map key presses to mouse ac

## Configuring mouse keys

Mouse keys supports two different modes to move the cursor:

* **Accelerated (default):** Holding movement keys accelerates the cursor until it reaches its maximum speed.
* **Constant:** Holding movement keys moves the cursor at constant speeds.

The same principle applies to scrolling.

Configuration options that are times, intervals or delays are given in milliseconds. Scroll speed is given as multiples of the default scroll step. For example, a scroll speed of 8 means that each scroll action covers 8 times the length of the default scroll step as defined by your operating system or application.

### Accelerated mode

This is the default mode. You can adjust the cursor and scrolling acceleration using the following settings in your keymap’s `config.h` file:
You can adjust the cursor and scrolling acceleration using the following settings in your keymap’s `config.h` file:

|Define |Default|Description |
|----------------------------|-------|---------------------------------------------------------|
Expand All @@ -65,55 +56,39 @@ Tips:

* Setting `MOUSEKEY_DELAY` too low makes the cursor unresponsive. Setting it too high makes small movements difficult.
* For smoother cursor movements, lower the value of `MOUSEKEY_INTERVAL`. If the refresh rate of your display is 60Hz, you could set it to `16` (1/60). As this raises the cursor speed significantly, you may want to lower `MOUSEKEY_MAX_SPEED`.
* Setting `MOUSEKEY_TIME_TO_MAX` or `MOUSEKEY_WHEEL_TIME_TO_MAX` to `0` will disable acceleration for the cursor or scrolling respectively. This way you can make one of them constant while keeping the other accelerated, which is not possible in constant speed mode.
* Setting `MOUSEKEY_TIME_TO_MAX` or `MOUSEKEY_WHEEL_TIME_TO_MAX` to `0` will disable acceleration for the cursor or scrolling respectively. This way you can even make one of them constant while keeping the other accelerated.

Cursor acceleration uses the same algorithm as the X Window System MouseKeysAccel feature. You can read more about it [on Wikipedia](https://en.wikipedia.org/wiki/Mouse_keys).

### Constant mode
## Configuring `KC_ACL_*` behavior

In this mode you can define multiple different speeds for both the cursor and the mouse wheel. There is no acceleration. `KC_ACL0`, `KC_ACL1` and `KC_ACL2` change the cursor and scroll speed to their respective setting.
You can define up to 3 different speeds for both the cursor and the mouse wheel. `KC_ACL0`, `KC_ACL1` and `KC_ACL2` change the cursor and scroll speed to their respective setting. There is no acceleration during a preset speed is activated.

You can choose whether speed selection is momentary or tap-to-select:

* **Momentary:** The chosen speed is only active while you hold the respective key. When the key is raised, mouse keys returns to the unmodified speed.
* **Tap-to-select:** The chosen speed is activated when you press the respective key and remains active even after the key has been raised. The default speed is that of `KC_ACL1`. There is no unmodified speed.

The default speeds from slowest to fastest are as follows:

* **Momentary:** `KC_ACL0` < `KC_ACL1` < *unmodified* < `KC_ACL2`
* **Tap-to-select:** `KC_ACL0` < `KC_ACL1` < `KC_ACL2`

To use constant speed mode, you must at least define `MK_3_SPEED` in your keymap’s `config.h` file:

```c
#define MK_3_SPEED
```
* **Momentary (default):** The chosen speed is only active while you hold the respective key. When the key is raised, mouse keys returns to the unmodified speed.
* **Tap-to-select:** The chosen speed is activated when you press the respective key and remains active even after the key has been raised.

To enable momentary mode, also define `MK_MOMENTARY_ACCEL`:
To enable tap-to-select mode, define `MOUSEKEY_PERSISTENT_ACCEL`:

```c
#define MK_MOMENTARY_ACCEL
#define MOUSEKEY_PERSISTENT_ACCEL
```

Use the following settings if you want to adjust cursor movement or scrolling:

|Define |Default |Description |
|---------------------|-------------|-------------------------------------------|
|`MK_3_SPEED` |*Not defined*|Enable constant cursor speeds |
|`MK_MOMENTARY_ACCEL` |*Not defined*|Enable momentary speed selection |
|`MK_C_OFFSET_UNMOD` |16 |Cursor offset per movement (unmodified) |
|`MK_C_INTERVAL_UNMOD`|16 |Time between cursor movements (unmodified) |
|`MK_C_OFFSET_0` |1 |Cursor offset per movement (`KC_ACL0`) |
|`MK_C_INTERVAL_0` |32 |Time between cursor movements (`KC_ACL0`) |
|`MK_C_OFFSET_1` |4 |Cursor offset per movement (`KC_ACL1`) |
|`MK_C_INTERVAL_1` |16 |Time between cursor movements (`KC_ACL1`) |
|`MK_C_OFFSET_2` |32 |Cursor offset per movement (`KC_ACL2`) |
|`MK_C_INTERVAL_2` |16 |Time between cursor movements (`KC_ACL2`) |
|`MK_W_OFFSET_UNMOD` |1 |Scroll steps per scroll action (unmodified)|
|`MK_W_INTERVAL_UNMOD`|40 |Time between scroll steps (unmodified) |
|`MK_W_OFFSET_0` |1 |Scroll steps per scroll action (`KC_ACL0`) |
|`MK_W_INTERVAL_0` |360 |Time between scroll steps (`KC_ACL0`) |
|`MK_W_OFFSET_1` |1 |Scroll steps per scroll action (`KC_ACL1`) |
|`MK_W_INTERVAL_1` |120 |Time between scroll steps (`KC_ACL1`) |
|`MK_W_OFFSET_2` |1 |Scroll steps per scroll action (`KC_ACL2`) |
|`MK_W_INTERVAL_2` |20 |Time between scroll steps (`KC_ACL2`) |
|Define |Default |Description |
|----------------------------|----------------------------|-------------------------------------------|
|`MOUSEKEY_PERSISTENT_ACCEL` |*Not defined* |Enable momentary speed selection |
|`MOUSEKEY_SPEED_0` |MOUSEKEY_MAX_SPEED / 4 |Cursor offset per movement (`KC_ACL0`) |
|`MOUSEKEY_INTERVAL_0` |MOUSEKEY_INTERVAL |Time between cursor movements (`KC_ACL0`) |
|`MOUSEKEY_SPEED_1` |MOUSEKEY_MAX_SPEED / 2 |Cursor offset per movement (`KC_ACL1`) |
|`MOUSEKEY_INTERVAL_1` |MOUSEKEY_INTERVAL |Time between cursor movements (`KC_ACL1`) |
|`MOUSEKEY_SPEED_2` |MOUSEKEY_MAX_SPEED |Cursor offset per movement (`KC_ACL2`) |
|`MOUSEKEY_INTERVAL_2` |MOUSEKEY_INTERVAL |Time between cursor movements (`KC_ACL2`) |
|`MOUSEKEY_WHEEL_SPEED_0` |MOUSEKEY_WHEEL_MAX_SPEED / 4|Scroll steps per scroll action (`KC_ACL0`) |
|`MOUSEKEY_WHEEL_INTERVAL_0` |MOUSEKEY_WHEEL_INTERVAL |Time between scroll steps (`KC_ACL0`) |
|`MOUSEKEY_WHEEL_SPEED_1` |MOUSEKEY_WHEEL_MAX_SPEED / 2|Scroll steps per scroll action (`KC_ACL1`) |
|`MOUSEKEY_WHEEL_INTERVAL_1` |MOUSEKEY_WHEEL_INTERVAL |Time between scroll steps (`KC_ACL1`) |
|`MOUSEKEY_WHEEL_SPEED_2` |MOUSEKEY_WHEEL_MAX_SPEED |Scroll steps per scroll action (`KC_ACL2`) |
|`MOUSEKEY_WHEEL_INTERVAL_2` |MOUSEKEY_WHEEL_INTERVAL |Time between scroll steps (`KC_ACL2`) |
52 changes: 45 additions & 7 deletions tmk_core/common/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,16 @@ static void mousekey_param_print(void) {
print("4: time_to_max: ");
pdec(mk_time_to_max);
print("\n");
print("5: wheel_max_speed: ");
print("5: wheel_delay(*10ms): ");
pdec(mk_wheel_delay);
print("\n");
print("6: wheel_interval(ms): ");
pdec(mk_wheel_interval);
print("\n");
print("7: wheel_max_speed: ");
pdec(mk_wheel_max_speed);
print("\n");
print("6: wheel_time_to_max: ");
print("8: wheel_time_to_max: ");
pdec(mk_wheel_time_to_max);
print("\n");
# endif /* !NO_PRINT */
Expand Down Expand Up @@ -638,13 +644,27 @@ static void mousekey_param_inc(uint8_t param, uint8_t inc) {
PRINT_SET_VAL(mk_time_to_max);
break;
case 5:
if (mk_wheel_delay + inc < UINT8_MAX)
mk_wheel_delay += inc;
else
mk_wheel_delay = UINT8_MAX;
PRINT_SET_VAL(mk_wheel_delay);
break;
case 6:
if (mk_wheel_interval + inc < UINT8_MAX)
mk_wheel_interval += inc;
else
mk_wheel_interval = UINT8_MAX;
PRINT_SET_VAL(mk_wheel_interval);
break;
case 7:
if (mk_wheel_max_speed + inc < UINT8_MAX)
mk_wheel_max_speed += inc;
else
mk_wheel_max_speed = UINT8_MAX;
PRINT_SET_VAL(mk_wheel_max_speed);
break;
case 6:
case 8:
if (mk_wheel_time_to_max + inc < UINT8_MAX)
mk_wheel_time_to_max += inc;
else
Expand Down Expand Up @@ -685,13 +705,27 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec) {
PRINT_SET_VAL(mk_time_to_max);
break;
case 5:
if (mk_wheel_delay > dec)
mk_wheel_delay -= dec;
else
mk_wheel_delay = 0;
PRINT_SET_VAL(mk_wheel_delay);
break;
case 6:
if (mk_wheel_interval > dec)
mk_wheel_interval -= dec;
else
mk_wheel_interval = 0;
PRINT_SET_VAL(mk_wheel_interval);
break;
case 7:
if (mk_wheel_max_speed > dec)
mk_wheel_max_speed -= dec;
else
mk_wheel_max_speed = 0;
PRINT_SET_VAL(mk_wheel_max_speed);
break;
case 6:
case 8:
if (mk_wheel_time_to_max > dec)
mk_wheel_time_to_max -= dec;
else
Expand All @@ -708,8 +742,10 @@ static void mousekey_console_help(void) {
"2: interval(ms)\n"
"3: max_speed\n"
"4: time_to_max\n"
"5: wheel_max_speed\n"
"6: wheel_time_to_max\n"
"5: wheel_delay(*10ms)\n"
"6: wheel_interval(ms)\n"
"7: wheel_max_speed\n"
"8: wheel_time_to_max\n"
"\n"
"p: print values\n"
"d: set defaults\n"
Expand Down Expand Up @@ -764,10 +800,12 @@ static bool mousekey_console(uint8_t code) {
mousekey_param_dec(mousekey_param, 10);
break;
case KC_D:
mk_delay = MOUSEKEY_DELAY / 10;
mk_delay = MOUSEKEY_DELAY/10;
mk_interval = MOUSEKEY_INTERVAL;
mk_max_speed = MOUSEKEY_MAX_SPEED;
mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
mk_wheel_delay = MOUSEKEY_WHEEL_DELAY/10;
mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
print("set default\n");
Expand Down
Loading