Why is WheelDelta = 120?
Asked Answered
F

4

16

I'm working with mouse events, specifically OnMouseWheel. Many code samples refer to distance the view changes (or zoom f.i. in 3D application) as Distance = Sign(WheelDelta)*Constant or Distance = WheelDelta / WHEEL_DELTA or something of that kind - assuming that WheelDelta is always a multiple of 120 (WHEEL_DELTA constant = 120).

I already found that in touch interfaces / tablets input may depend on scrolling length.

I was wondering why Microsoft has set default WheelDelta to 120, why not 100 or 10 or anything else? In what other cases wheel delta may be something different from 120?

Fruge answered 13/10, 2011 at 11:2 Comment(1)
120 was chosen because it has more factors than 100.Ibeam
P
8

WHEEL_DELTA is not fixed anymore to 120. As I understand it this constant was chosen to allow for finer resolutions in the future, which obviously is NOW.

See this article from MSDN

Paprika answered 13/10, 2011 at 11:18 Comment(3)
From the MSDN docs on WM_MOUSEWHEEL (msdn.microsoft.com/en-us/library/windows/desktop/…): "The delta was set to 120 to allow Microsoft or other vendors to build finer-resolution wheels (a freely-rotating wheel with no notches) to send more messages per rotation, but with a smaller value in each message. To use this feature, you can either add the incoming delta values until WHEEL_DELTA is reached (so for a delta-rotation you get the same response), or scroll partial lines in response to the more frequent messages."Median
Updated MSDN link for WM_MOUSEWHEEL: msdn.microsoft.com/en-us/library/windows/desktop/…Stillas
WHEEL_DELTA expands to 120 as it always has. Its definition has not been changed. Its meaning has not changed either. It is the delta value which corresponds to one notch (on a wheel that has notches). A delta less than WHEEL_DELTA means a turn through less than a full notch.Psychodynamics
N
11

The Qt Documentation elaborates a bit more on why it is actually 120:

QPoint QWheelEvent::angleDelta() const

Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user.

Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.

However, some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event.

https://doc.qt.io/qt-5/qwheelevent.html#angleDelta

Norvan answered 14/5, 2013 at 11:16 Comment(2)
+1, but still that does not answers why it's chosen to be 1/8 and not e.g. 1/10 or 1/2.Fruge
I could guess, that you need 3 bits for representing 8 values. 0..7. This might explain why 1/10 is not used. And I guess 1/2 is not used as it is not fine grained enough. However, I'm just guessing and I really don't know.Norvan
P
8

WHEEL_DELTA is not fixed anymore to 120. As I understand it this constant was chosen to allow for finer resolutions in the future, which obviously is NOW.

See this article from MSDN

Paprika answered 13/10, 2011 at 11:18 Comment(3)
From the MSDN docs on WM_MOUSEWHEEL (msdn.microsoft.com/en-us/library/windows/desktop/…): "The delta was set to 120 to allow Microsoft or other vendors to build finer-resolution wheels (a freely-rotating wheel with no notches) to send more messages per rotation, but with a smaller value in each message. To use this feature, you can either add the incoming delta values until WHEEL_DELTA is reached (so for a delta-rotation you get the same response), or scroll partial lines in response to the more frequent messages."Median
Updated MSDN link for WM_MOUSEWHEEL: msdn.microsoft.com/en-us/library/windows/desktop/…Stillas
WHEEL_DELTA expands to 120 as it always has. Its definition has not been changed. Its meaning has not changed either. It is the delta value which corresponds to one notch (on a wheel that has notches). A delta less than WHEEL_DELTA means a turn through less than a full notch.Psychodynamics
V
4

The question is marked as answered already I thought I might provide some more information.

If I understand correctly, WHEEL_DELTA is actually 40 not 120, the 120 comes from the mouse driver multiplying the raw WHEEL_DELTA value by the number of lines to scroll, which is by default 3. You can obtain the scroll line number using

My.Computer.Mouse.WheelScrollLines

This can most easily be seen using a NumericUpDown control, which on scroll adjusts the value by the increment multiplied by that line count.

Just messing with my wheel mouse, there are 18 detents in a full revolution, being 20 degrees per detent (Sure I know that's a small sample size of mouses in the world...!). 40 suggests they felt half degrees were fine enough though this last paragraph is supposition.

EDIT: Not one to spread misinformation, on further study WHEEL_DELTA is in fact 120, NumericUpDown proved to be a false positive. Nonetheless, the rest of the discussion is valid, if one can apply a factor of three to the logic.

Veto answered 13/10, 2011 at 19:15 Comment(4)
In Delphi.Windows.pas WHEEL_DELTA = 120; I guess if you'd set WheelScrollLines to 4 it will become 4, but no connection to WheelDelta which will remain 120. Hence my original question :)Fruge
Yup I threw that correction in there, it is always 120. I guess my main thought actually is about divisibility, since like with degree angles, 120 is evenly divisible by a bunch of different numbers.Veto
In WinUser.h there is #define WHEEL_DELTA 120.Incapacitate
@J Collins Which is also why there are 12 inches in a foot.Skyla
M
0

As you have noticed laptop Touchpads can scroll (either two-finger or scroll zone on right hand size), in which case there can be lots of events with very small wheelDelta values (either needing integration, or perhaps timeouts to prevent too many redraws).

Also different OS's or configurations or devices can have different meanings for scrolling - pixels, lines, or pages. e.g. DOM event.deltaMode

Finally some devices (mice and touchpads) also allow horizontal scrolling.

The above is more specific to browser DOM events, but the same issues may apply to Win events too.

Edit:

From the Firefox MDN docs there are three events you are probably interested in: WM_MOUSEWHEEL, WM_MOUSEHWHEEL, and WM_GESTURE (panning on touch devices).

A search of the Mozilla Bugzilla database shows a variety of problems with some Symantics and ALPS touch drivers sending WM_VSCROLL instead of WM_MOUSEWHEEL (may be relevant if supporting touchpads).

If you want horizontal mouse scrolling support, this article from a flash dev says: [mousewheel support] was added in Vista so if you are using XP or 2000 you need IntelliType Pro and/or IntelliPoint installed for WM_MOUSEHWHEEL support.

@Krom: more speculations and loose facts but maybe useful to others :-)

Median answered 5/10, 2012 at 3:23 Comment(1)
I don't see an answer here, just some speculations and loosely related facts.Fruge

© 2022 - 2024 — McMap. All rights reserved.