Lately I’ve been doing a lot of work on a fairly complex LabVIEW application. It utilizes a number of controls and indicators which have vertical scrollbars (e.g. text boxes and arrays). This gives users access to a great deal of data without over-crowding the front panel. Unfortunately, LabVIEW does not natively support scrolling via the mouse wheel. Well, I happen to like the scroll wheel, and so do many of my users. So this week I finally went online and found a fairly straight-forward means of implementing this functionality. You don’t need any crazy DLL calls or APIs; LabVIEW’s “Input Device Control” palette offers this functionality (located under the “Connectivity” section). I found this particular example very helpful.
I did run into one rather odd problem though. On my computer, the “Scrolling” value I get using the “Acquire Input Data” block is differential, not absolute. In other words, when I move the wheel one step, the value of “Scrolling” is 120. If I scroll no further and poll again, “Scrolling” is back to 0. However, on the second computer I used to test this function, I received an absolute value. In other words, if I move the wheel one step, the value of “Scrolling” is 120, but then it remains at 120 until I move the wheel again. For instance, if I move the wheel by one additional step, “Scrolling” is now 240; the overall value is cumulative (an absolute position).
To combat this problem, I came up with a fairly simple (but not exactly elegant) algorithm that attempts to detect the mouse type based on the first few values of “Scrolling.” If the absolute value of this parameter ever exceeds 3000, we assume the mouse is of the “absolute” variety. Otherwise, if we’ve seen this value change more than 10 times without exceeding 3000, we assume it is of the “incremental” variety. Until these 10 changes are seen, all scroll input is ignored. This can be a bit frustrating, since the first time a user attempts to scroll something, they’ll have to move the wheel for a second or two before the GUI responds. However, in the case of my application, I then store the mouse type in the registry, so that the next time the program is launched, the scroll wheel is immediately functional. No big deal. If anyone out there has better ideas though, feel free to let me know!
Anyway, you can click on the block diagram below to get a larger view of a quick demo application I built. This demo shows how you might use the scroll wheel to control text boxes, arrays, sliders, and even graph axis scaling. You can also download the example ZIP file below. Feel free to leave comments or questions below. Thanks!
Download: scrollwheel_example.zip (85KB)