Tag Archives: mouse

LabVIEW: Using the Mouse Scroll Wheel

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!

LabVIEW Scroll Wheel Example - Block Diagram

LabVIEW Scroll Wheel Example - Front Panel

Download: scrollwheel_example.zip (85KB)

Small Stuff: An Optical Mouse Sensor

A few weeks ago I was given a broken Microsoft Wireless Optical Mouse 4000.  When powered on, its LED glowed and appeared to blink and fade as expected, depending on whether or not the mouse sensed motion.  The USB receiver seemed to be working fine as well; Windows detected it and installed the appropriate drivers.  And yet no mouse clicks or motions would register.  So I decided to open it up and take a look.  Long story short: I couldn’t find any obvious problems, but I did snap a few pictures of its optical sensor.  Sadly, I can’t find a datasheet for this particular part.  One document I found called it a Microsoft proprietary sensor.  Oh well.  Here are some nifty pictures taken with a sweet microscope I have access to through work:

Other cool links on the subject:

  • The optical mouse cam (an optical mouse text scanner)
  • An overview of various optical mice and sensors (a bit older, but still cool)
  • More neat pictures of the same sensor (and possibly the same mouse?)
  • A datasheet for the VD5376 optical mouse sensor (comparable, not identical)