aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Weimar <mail@markusweimar.de>2018-10-17 10:40:52 +0200
committerDrashna Jaelre <drashna@live.com>2019-04-18 23:31:17 -0700
commite3a940026ead4a3b4d0a9f536bd4cc5153e4140b (patch)
tree386ffae9f33da9318d559c7980dd28fb7de282f3
parent74af596d8ac0e1ee5f308f520b22831ca32f0339 (diff)
downloadqmk_firmware-e3a940026ead4a3b4d0a9f536bd4cc5153e4140b.tar.gz
qmk_firmware-e3a940026ead4a3b4d0a9f536bd4cc5153e4140b.zip
Improve mouse keys docs and constant speed mode
-rw-r--r--docs/feature_mouse_keys.md161
-rw-r--r--tmk_core/common/mousekey.c29
-rw-r--r--tmk_core/common/mousekey.h60
3 files changed, 136 insertions, 114 deletions
diff --git a/docs/feature_mouse_keys.md b/docs/feature_mouse_keys.md
index e64ddf3d0..75633969e 100644
--- a/docs/feature_mouse_keys.md
+++ b/docs/feature_mouse_keys.md
@@ -1,114 +1,121 @@
1# Mousekeys 1# Mouse keys
2 2
3Mouse keys is a feature that allows you to emulate a mouse using your keyboard. You can move the pointer at different speeds, press 5 buttons and scroll in all 8 directions.
3 4
4Mousekeys is a feature that allows you to emulate a mouse using your keyboard. You can move the pointer around, click up to 5 buttons, and even scroll in all 4 directions. 5## Adding mouse keys to your keyboard
5 6
6There are 2 ways to define how the mousekeys behave, using "[auto-accelerating](#configuring-the-behavior-of-mousekeys-with-auto-accelerated-movement)" or "[3-speed constant](#configuring-the-behavior-of-mousekeys-with-3-speed-constant-movement)" behavior. 7To use mouse keys, you must at least enable mouse keys support and map mouse actions to keys on your keyboard.
7 8
8In either case, you will need to enable mousekeys in your makefile, 9### Enabling mouse keys
9and add the relevant [keycodes](#mapping-mouse-actions-to-keyboard-keys) to your keymap.
10 10
11#### Enable Mousekeys 11To enable mouse keys, add the following line to your keymap’s `rules.mk`:
12 12
13To enable the mousekey functionality, add the following line to your keymap's `rules.mk`: 13```c
14
15```
16MOUSEKEY_ENABLE = yes 14MOUSEKEY_ENABLE = yes
17``` 15```
18 16
19#### Mapping Mouse Actions to Keyboard Keys 17### Mapping mouse actions
20 18
21You can use these keycodes within your keymap to map button presses to mouse actions: 19In your keymap you can use the following keycodes to map key presses to mouse actions:
22 20
23|Key |Aliases |Description | 21|Key |Aliases |Description |
24|----------------|---------|-----------------------------------| 22|----------------|---------|-----------------|
25|`KC_MS_UP` |`KC_MS_U`|Mouse Cursor Up | 23|`KC_MS_UP` |`KC_MS_U`|Move cursor up |
26|`KC_MS_DOWN` |`KC_MS_D`|Mouse Cursor Down | 24|`KC_MS_DOWN` |`KC_MS_D`|Move cursor down |
27|`KC_MS_LEFT` |`KC_MS_L`|Mouse Cursor Left | 25|`KC_MS_LEFT` |`KC_MS_L`|Move cursor left |
28|`KC_MS_RIGHT` |`KC_MS_R`|Mouse Cursor Right | 26|`KC_MS_RIGHT` |`KC_MS_R`|Move cursor right|
29|`KC_MS_BTN1` |`KC_BTN1`|Mouse Button 1 | 27|`KC_MS_BTN1` |`KC_BTN1`|Press button 1 |
30|`KC_MS_BTN2` |`KC_BTN2`|Mouse Button 2 | 28|`KC_MS_BTN2` |`KC_BTN2`|Press button 2 |
31|`KC_MS_BTN3` |`KC_BTN3`|Mouse Button 3 | 29|`KC_MS_BTN3` |`KC_BTN3`|Press button 3 |
32|`KC_MS_BTN4` |`KC_BTN4`|Mouse Button 4 | 30|`KC_MS_BTN4` |`KC_BTN4`|Press button 4 |
33|`KC_MS_BTN5` |`KC_BTN5`|Mouse Button 5 | 31|`KC_MS_BTN5` |`KC_BTN5`|Press button 5 |
34|`KC_MS_WH_UP` |`KC_WH_U`|Mouse Wheel Up | 32|`KC_MS_WH_UP` |`KC_WH_U`|Move wheel up |
35|`KC_MS_WH_DOWN` |`KC_WH_D`|Mouse Wheel Down | 33|`KC_MS_WH_DOWN` |`KC_WH_D`|Move wheel down |
36|`KC_MS_WH_LEFT` |`KC_WH_L`|Mouse Wheel Left | 34|`KC_MS_WH_LEFT` |`KC_WH_L`|Move wheel left |
37|`KC_MS_WH_RIGHT`|`KC_WH_R`|Mouse Wheel Right | 35|`KC_MS_WH_RIGHT`|`KC_WH_R`|Move wheel right |
38|`KC_MS_ACCEL0` |`KC_ACL0`|Set mouse acceleration to 0(slow) | 36|`KC_MS_ACCEL0` |`KC_ACL0`|Set speed to 0 |
39|`KC_MS_ACCEL1` |`KC_ACL1`|Set mouse acceleration to 1(medium)| 37|`KC_MS_ACCEL1` |`KC_ACL1`|Set speed to 1 |
40|`KC_MS_ACCEL2` |`KC_ACL2`|Set mouse acceleration to 2(fast) | 38|`KC_MS_ACCEL2` |`KC_ACL2`|Set speed to 2 |
41 39
40For an example, see [the mouse layer in this keymap](https://github.com/qmk/qmk_firmware/blob/1df10ae3bfc146805c75b06dc0c126cd1ef3a60a/keyboards/clueboard/66/keymaps/mouse_keys/keymap.c#L40).
42 41
43## Configuring the Behavior of Mousekeys with auto-accelerated movement 42## Configuring mouse keys
44 43
45This behavior is intended to emulate the X Window System MouseKeysAccel feature. You can read more about it [on Wikipedia](https://en.wikipedia.org/wiki/Mouse_keys). 44Mouse keys supports two different modes to move the cursor:
46 45
47The default speed for controlling the mouse with the keyboard is intentionally slow. You can adjust these parameters by adding these settings to your keymap's `config.h` file. All times are specified in milliseconds (ms). 46* **Accelerated (default):** Holding movement keys accelerates the cursor until it reaches its maximum speed.
47* **Constant:** Holding movement keys moves the cursor at constant speeds.
48 48
49``` 49The same principle applies to scrolling.
50#define MOUSEKEY_DELAY 300
51#define MOUSEKEY_INTERVAL 50
52#define MOUSEKEY_MAX_SPEED 10
53#define MOUSEKEY_TIME_TO_MAX 20
54#define MOUSEKEY_WHEEL_MAX_SPEED 8
55#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
56```
57 50
58#### `MOUSEKEY_DELAY` 51Configuration 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.
59 52
60When one of the mouse movement buttons is pressed this setting is used to define the delay between that button press and the mouse cursor moving. Some people find that small movements are impossible if this setting is too low, while settings that are too high feel sluggish. 53### Accelerated mode
61 54
62#### `MOUSEKEY_INTERVAL` 55This is the default mode. You can adjust the cursor and scrolling acceleration using the following settings in your keymap’s `config.h` file:
63 56
64When a movement key is held down this specifies how long to wait between each movement report. Lower settings will translate into an effectively higher mouse speed. 57|Define |Default|Description |
58|----------------------------|-------|---------------------------------------------------------|
59|`MOUSEKEY_DELAY` |300 |Delay between pressing a movement key and cursor movement|
60|`MOUSEKEY_INTERVAL` |50 |Time between cursor movements |
61|`MOUSEKEY_MAX_SPEED` |10 |Maximum cursor speed at which acceleration stops |
62|`MOUSEKEY_TIME_TO_MAX` |20 |Time until maximum cursor speed is reached |
63|`MOUSEKEY_WHEEL_MAX_SPEED` |8 |Maximum number of scroll steps per scroll action |
64|`MOUSEKEY_WHEEL_TIME_TO_MAX`|40 |Time until maximum scroll speed is reached |
65 65
66#### `MOUSEKEY_MAX_SPEED` 66Tips:
67 67
68As a movement key is held down the speed of the mouse cursor will increase until it reaches `MOUSEKEY_MAX_SPEED`. 68* Setting `MOUSEKEY_DELAY` too low makes the cursor unresponsive. Setting it too high makes small movements difficult.
69* 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`.
70* 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.
69 71
70#### `MOUSEKEY_TIME_TO_MAX` 72Cursor 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).
71 73
72How long you want to hold down a movement key for until `MOUSEKEY_MAX_SPEED` is reached. This controls how quickly your cursor will accelerate. 74### Constant mode
73 75
74#### `MOUSEKEY_WHEEL_MAX_SPEED` 76In 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.
75 77
76The top speed for scrolling movements. 78You can choose whether speed selection is momentary or tap-to-select:
77 79
78#### `MOUSEKEY_WHEEL_TIME_TO_MAX` 80* **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.
81* **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.
79 82
80How long you want to hold down a scroll key for until `MOUSEKEY_WHEEL_MAX_SPEED` is reached. This controls how quickly your scrolling will accelerate. 83The default speeds from slowest to fastest are as follows:
81 84
85* **Momentary:** `KC_ACL0` < `KC_ACL1` < *unmodified* < `KC_ACL2`
86* **Tap-to-select:** `KC_ACL0` < `KC_ACL1` < `KC_ACL2`
82 87
83## Configuring the Behavior of Mousekeys with 3-speed constant movement 88To use constant speed mode, you must at least define `MK_3_SPEED` in your keymap’s `config.h` file:
84 89
85In your keymap's `config.h`, you must add the line: 90```c
86```
87#define MK_3_SPEED 91#define MK_3_SPEED
88``` 92```
89Then you can precisely define 3 different speeds for both the cursor and the mouse wheel, and also whether speed selection is momentary or tap-to-select.
90For each speed, you can specify how many milliseconds you want between reports(interval), and how far you want to it to move per report(offset).
91 93
92For example: 94To enable momentary mode, also define `MK_MOMENTARY_ACCEL`:
93 95
94``` 96```c
95#define MK_3_SPEED 97#define MK_MOMENTARY_ACCEL
96#define MK_MOMENTARY_ACCEL // comment this out for tap-to-select acceleration
97// cursor speeds:
98#define MK_C_OFFSET_SLOW 1 // pixels
99#define MK_C_INTERVAL_SLOW 100 // milliseconds
100#define MK_C_OFFSET_MED 4
101#define MK_C_INTERVAL_MED 16
102#define MK_C_OFFSET_FAST 12
103#define MK_C_INTERVAL_FAST 16
104// scroll wheel speeds:
105#define MK_W_OFFSET_SLOW 1 // wheel clicks
106#define MK_W_INTERVAL_SLOW 400 // milliseconds
107#define MK_W_OFFSET_MED 1
108#define MK_W_INTERVAL_MED 200
109#define MK_W_OFFSET_FAST 1
110#define MK_W_INTERVAL_FAST 100
111``` 98```
112 99
113Medium values will be used as the default or unmodified speed. 100Use the following settings if you want to adjust cursor movement or scrolling:
114The speed at which both the cursor and scrolling move can be selected with KC_ACL0, KC_ACL1, KC_ACL2 for slow, medium, and fast. However, if you leave MK_MOMENTARY_ACCEL defined then there is no need to ever send KC_ACL1, since that will be the unmodified speed. 101
102|Define |Default |Description |
103|---------------------|-------------|-------------------------------------------|
104|`MK_3_SPEED` |*Not defined*|Enable constant cursor speeds |
105|`MK_MOMENTARY_ACCEL` |*Not defined*|Enable momentary speed selection |
106|`MK_C_OFFSET_UNMOD` |16 |Cursor offset per movement (unmodified) |
107|`MK_C_INTERVAL_UNMOD`|16 |Time between cursor movements (unmodified) |
108|`MK_C_OFFSET_0` |1 |Cursor offset per movement (`KC_ACL0`) |
109|`MK_C_INTERVAL_0` |32 |Time between cursor movements (`KC_ACL0`) |
110|`MK_C_OFFSET_1` |4 |Cursor offset per movement (`KC_ACL1`) |
111|`MK_C_INTERVAL_1` |16 |Time between cursor movements (`KC_ACL1`) |
112|`MK_C_OFFSET_2` |32 |Cursor offset per movement (`KC_ACL2`) |
113|`MK_C_INTERVAL_2` |16 |Time between cursor movements (`KC_ACL2`) |
114|`MK_W_OFFSET_UNMOD` |1 |Scroll steps per scroll action (unmodified)|
115|`MK_W_INTERVAL_UNMOD`|40 |Time between scroll steps (unmodified) |
116|`MK_W_OFFSET_0` |1 |Scroll steps per scroll action (`KC_ACL0`) |
117|`MK_W_INTERVAL_0` |360 |Time between scroll steps (`KC_ACL0`) |
118|`MK_W_OFFSET_1` |1 |Scroll steps per scroll action (`KC_ACL1`) |
119|`MK_W_INTERVAL_1` |120 |Time between scroll steps (`KC_ACL1`) |
120|`MK_W_OFFSET_2` |1 |Scroll steps per scroll action (`KC_ACL2`) |
121|`MK_W_INTERVAL_2` |20 |Time between scroll steps (`KC_ACL2`) |
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 87239fbb7..8c9184306 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -171,28 +171,31 @@ void mousekey_off(uint8_t code) {
171 171
172 172
173enum { 173enum {
174 mkspd_slow, 174 mkspd_unmod,
175 mkspd_med, 175 mkspd_0,
176 mkspd_fast, 176 mkspd_1,
177 mkspd_2,
177 mkspd_COUNT 178 mkspd_COUNT
178}; 179};
179static uint8_t mk_speed = mkspd_med; 180#ifndef MK_MOMENTARY_ACCEL
180#ifdef MK_MOMENTARY_ACCEL 181static uint8_t mk_speed = mkspd_1;
181static uint8_t mkspd_DEFAULT = mkspd_med; 182#else
183static uint8_t mk_speed = mkspd_unmod;
184static uint8_t mkspd_DEFAULT = mkspd_unmod;
182#endif 185#endif
183static uint16_t last_timer_c = 0; 186static uint16_t last_timer_c = 0;
184static uint16_t last_timer_w = 0; 187static uint16_t last_timer_w = 0;
185uint16_t c_offsets[mkspd_COUNT] = { 188uint16_t c_offsets[mkspd_COUNT] = {
186 MK_C_OFFSET_SLOW, MK_C_OFFSET_MED, MK_C_OFFSET_FAST 189 MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2
187}; 190};
188uint16_t c_intervals[mkspd_COUNT] = { 191uint16_t c_intervals[mkspd_COUNT] = {
189 MK_C_INTERVAL_SLOW, MK_C_INTERVAL_MED, MK_C_INTERVAL_FAST 192 MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2
190}; 193};
191uint16_t w_offsets[mkspd_COUNT] = { 194uint16_t w_offsets[mkspd_COUNT] = {
192 MK_W_OFFSET_SLOW, MK_W_OFFSET_MED, MK_W_OFFSET_FAST 195 MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2
193}; 196};
194uint16_t w_intervals[mkspd_COUNT] = { 197uint16_t w_intervals[mkspd_COUNT] = {
195 MK_W_INTERVAL_SLOW, MK_W_INTERVAL_MED, MK_W_INTERVAL_FAST 198 MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2
196}; 199};
197 200
198 201
@@ -254,9 +257,9 @@ void mousekey_on(uint8_t code) {
254 else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; 257 else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3;
255 else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; 258 else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4;
256 else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; 259 else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5;
257 else if (code == KC_MS_ACCEL0) mk_speed = mkspd_slow; 260 else if (code == KC_MS_ACCEL0) mk_speed = mkspd_0;
258 else if (code == KC_MS_ACCEL1) mk_speed = mkspd_med; 261 else if (code == KC_MS_ACCEL1) mk_speed = mkspd_1;
259 else if (code == KC_MS_ACCEL2) mk_speed = mkspd_fast; 262 else if (code == KC_MS_ACCEL2) mk_speed = mkspd_2;
260 if (mk_speed != old_speed) adjust_speed(); 263 if (mk_speed != old_speed) adjust_speed();
261} 264}
262 265
diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h
index ce3501b23..89c1eaf11 100644
--- a/tmk_core/common/mousekey.h
+++ b/tmk_core/common/mousekey.h
@@ -64,42 +64,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
64 64
65#else /* #ifndef MK_3_SPEED */ 65#else /* #ifndef MK_3_SPEED */
66 66
67#ifndef MK_C_OFFSET_SLOW 67#ifndef MK_C_OFFSET_UNMOD
68#define MK_C_OFFSET_SLOW 1 68#define MK_C_OFFSET_UNMOD 16
69#endif 69#endif
70#ifndef MK_C_INTERVAL_SLOW 70#ifndef MK_C_INTERVAL_UNMOD
71#define MK_C_INTERVAL_SLOW 100 71#define MK_C_INTERVAL_UNMOD 16
72#endif 72#endif
73#ifndef MK_C_OFFSET_MED 73#ifndef MK_C_OFFSET_0
74#define MK_C_OFFSET_MED 4 74#define MK_C_OFFSET_0 1
75#endif 75#endif
76#ifndef MK_C_INTERVAL_MED 76#ifndef MK_C_INTERVAL_0
77#define MK_C_INTERVAL_MED 16 77#define MK_C_INTERVAL_0 32
78#endif 78#endif
79#ifndef MK_C_OFFSET_FAST 79#ifndef MK_C_OFFSET_1
80#define MK_C_OFFSET_FAST 12 80#define MK_C_OFFSET_1 4
81#endif 81#endif
82#ifndef MK_C_INTERVAL_FAST 82#ifndef MK_C_INTERVAL_1
83#define MK_C_INTERVAL_FAST 16 83#define MK_C_INTERVAL_1 16
84#endif
85#ifndef MK_C_OFFSET_2
86#define MK_C_OFFSET_2 32
87#endif
88#ifndef MK_C_INTERVAL_2
89#define MK_C_INTERVAL_2 16
84#endif 90#endif
85 91
86#ifndef MK_W_OFFSET_SLOW 92#ifndef MK_W_OFFSET_UNMOD
87#define MK_W_OFFSET_SLOW 1 93#define MK_W_OFFSET_UNMOD 1
94#endif
95#ifndef MK_W_INTERVAL_UNMOD
96#define MK_W_INTERVAL_UNMOD 40
97#endif
98#ifndef MK_W_OFFSET_0
99#define MK_W_OFFSET_0 1
88#endif 100#endif
89#ifndef MK_W_INTERVAL_SLOW 101#ifndef MK_W_INTERVAL_0
90#define MK_W_INTERVAL_SLOW 400 102#define MK_W_INTERVAL_0 360
91#endif 103#endif
92#ifndef MK_W_OFFSET_MED 104#ifndef MK_W_OFFSET_1
93#define MK_W_OFFSET_MED 1 105#define MK_W_OFFSET_1 1
94#endif 106#endif
95#ifndef MK_W_INTERVAL_MED 107#ifndef MK_W_INTERVAL_1
96#define MK_W_INTERVAL_MED 200 108#define MK_W_INTERVAL_1 120
97#endif 109#endif
98#ifndef MK_W_OFFSET_FAST 110#ifndef MK_W_OFFSET_2
99#define MK_W_OFFSET_FAST 1 111#define MK_W_OFFSET_2 1
100#endif 112#endif
101#ifndef MK_W_INTERVAL_FAST 113#ifndef MK_W_INTERVAL_2
102#define MK_W_INTERVAL_FAST 100 114#define MK_W_INTERVAL_2 20
103#endif 115#endif
104 116
105#endif /* #ifndef MK_3_SPEED */ 117#endif /* #ifndef MK_3_SPEED */