Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is WheelDelta = 120?

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?

like image 869
Kromster Avatar asked Oct 13 '11 11:10

Kromster


3 Answers

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

like image 153
math Avatar answered Nov 19 '22 00:11

math


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.

like image 31
J Collins Avatar answered Nov 19 '22 00:11

J Collins


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

like image 8
codencandy Avatar answered Nov 18 '22 23:11

codencandy