aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2022-01-06 00:30:22 -0800
committerGitHub <noreply@github.com>2022-01-06 00:30:22 -0800
commit2669b0bee89a212a7e3aadf83f484bfb285a9897 (patch)
tree84c66420b42855e75dbe574e256f04a215f87ef7
parentf5d11e758630968fa7e7c876d5aaeb0835844ca3 (diff)
downloadqmk_firmware-2669b0bee89a212a7e3aadf83f484bfb285a9897.tar.gz
qmk_firmware-2669b0bee89a212a7e3aadf83f484bfb285a9897.zip
[Docs] Add drag scrolling example to Pointing device docs page (#15715)
Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
-rw-r--r--docs/feature_pointing_device.md36
1 files changed, 34 insertions, 2 deletions
diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md
index bd7fb3658..098a787ed 100644
--- a/docs/feature_pointing_device.md
+++ b/docs/feature_pointing_device.md
@@ -220,9 +220,11 @@ Additionally, by default, `pointing_device_send()` will only send a report when
220 220
221Also, you use the `has_mouse_report_changed(new, old)` function to check to see if the report has changed. 221Also, you use the `has_mouse_report_changed(new, old)` function to check to see if the report has changed.
222 222
223## Example 223## Examples
224 224
225In the following example, a custom key is used to click the mouse and scroll 127 units vertically and horizontally, then undo all of that when released - because that's a totally useful function. Listen, this is an example: 225### Custom Mouse Keycode
226
227In this example, a custom key is used to click the mouse and scroll 127 units vertically and horizontally, then undo all of that when released - because that's a totally useful function.
226 228
227```c 229```c
228case MS_SPECIAL: 230case MS_SPECIAL:
@@ -242,3 +244,33 @@ case MS_SPECIAL:
242``` 244```
243 245
244Recall that the mouse report is set to zero (except the buttons) whenever it is sent, so the scrolling would only occur once in each case. 246Recall that the mouse report is set to zero (except the buttons) whenever it is sent, so the scrolling would only occur once in each case.
247
248### Drag Scroll or Mouse Scroll
249
250A very common implementation is to use the mouse movement to scroll instead of moving the cursor on the system. This uses the `pointing_device_task_user` callback to intercept and modify the mouse report before it's sent to the host system.
251
252```c
253enum custom_keycodes {
254 DRAG_SCROLL = SAFE_RANGE,
255};
256
257bool set_scrolling = false;
258
259report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
260 if (set_scrolling) {
261 mouse_report.h = mouse_report.x;
262 mouse_report.v = mouse_report.y;
263 mouse_report.x = mouse_report.y = 0
264 }
265 return mouse_report;
266}
267
268bool process_record_user(uint16_t keycode, keyrecord_t *record) {
269 if (keycode == DRAG_SCROLL && record->event.pressed) {
270 set_scrolling = !set_scrolling;
271 }
272 return true;
273}
274```
275
276This allows you to toggle between scrolling and cursor movement by pressing the DRAG_SCROLL key.