{"id":104773,"date":"2021-01-29T07:00:00","date_gmt":"2021-01-29T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=104773"},"modified":"2021-01-28T07:19:39","modified_gmt":"2021-01-28T15:19:39","slug":"20210129-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210129-00\/?p=104773","title":{"rendered":"Autoscrolling on drag, part 5: Adding wiggle-to-scroll to escape velocity"},"content":{"rendered":"<p>Last time, we implemented <a title=\"Autoscrolling on drag, part 4: Dynamic autoscroll based on escape velocity\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210128-00\/?p=104768\"> autoscroll speed based on the mouse&#8217;s velocity<\/a>. But our implementation didn&#8217;t support the popular bug-that-is-now-a-feature where wiggling the mouse makes the window scroll faster. Let&#8217;s bring that back.<\/p>\n<pre>void OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)\r\n{\r\n    if (g_fDragging) {\r\n        if (g_dyAutoScroll == 0) {\r\n            int direction = DetectAutoScroll({ x, y });\r\n            if (direction) {\r\n                DWORD tmTimer = GetDoubleClickTime() \/ 5;\r\n                auto [distance, time] = GetMouseVelocity(hwnd, { x, y });\r\n                if (time != 0) {\r\n                    g_dyAutoScroll = MulDiv(distance, tmTimer, time);\r\n                } else {\r\n                    g_dyAutoScroll = 0;\r\n                }\r\n                if (g_dyAutoScroll &gt; -g_cyLine &amp;&amp; g_dyAutoScroll &lt; g_cyLine) {\r\n                    g_dyAutoScroll = direction * g_cyLine;\r\n                }\r\n                SetTimer(hwnd, IDT_AUTOSCROLL, tmTimer, OnAutoScroll);\r\n            }\r\n        } else {\r\n            <span style=\"color: blue;\">HandleDragMouseMove(hwnd, { x, y });<\/span>\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>In the case where the mouse moved when autoscroll was already active (<code>g_dyAutoScroll<\/code> is nonzero), we let <code>Handle\u00adDrag\u00adMouse\u00adMove<\/code> do the work of processing the mouse movement. Recall that that function checks whether the mouse is in a place that activates autoscroll. If so, then it <i>triggers an autoscroll immediately<\/i>; otherwise, it cancels autoscroll.<\/p>\n<p>And there you have it, scrolling faster by wiggling the mouse. The bug that&#8217;s now a feature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reintroducing a bug that&#8217;s now a feature.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-104773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Reintroducing a bug that&#8217;s now a feature.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=104773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=104773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=104773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=104773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}