How does mouse technology work?

Status
Not open for further replies.
The mouse has been around a long time and has worked very well on much slower technology than we have today. We have come to take it for granted that a mouse can move over the top of many windows and features within windows, changing shape and recording clicks even in systems with a heavy work load. I once saw a documentary about the rivalry between Apple and Microsoft in the DOS days when engineers from both companies were looking at the first mouse based system from Xerox (this is pre-Lisa and Macintosh). One thing I'll never forget was how amazed the engineers were about how easily the cursor moved over the top of underlying graphics without hesitating or distorting the graphics as it moved.

I never have understood the hardware and software interaction that allows the mouse to do what we have come to take for granted. How does the mouse and cursor keep track of the position with such precision especially when the display has high resolution? How frequently does the hardware receive an interrupt with positional information? How does the drawing software work interact with video memory? I'm asking these questions in the OS forum rather than the hardware forum because I think the understanding the how the OS software interacts with the hardware is key to understanding how it all works as a whole.
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
It depends on the mouse interface. If it's a serial mouse, you handle it like a serial device. If it's USB, then it's a USB handler. Once you get called, you read the data and handle it as you like, handing data back to the OS. Basically, think of it handing back X,Y coordinates as well as state such as which, if any, buttons are pressed, etc. The OS handles the bits about selecting objects. As to moving the pointer around on the screen, there are a number of ways to do it... there were "hardware cursor" options as well as software.
 
Thanks Fitten. The mouse management classes in various languages show what states the OS presents to the high level programmer. I am trying to understand what goes on down in the USB handler as an example. If we are talking about an optical mouse on a USB port, the "How stuff works" article says:

Refresh rate -- it is how often the sensor samples images as you move the mouse. Faster is generally better, assuming the other mouse components can process them. Rates range from 1500 to 6000 samples per second.

I assume this means that ... if I am sweeping a mouse across a screen full of windows and the mouse is changing shape as it moves through hyper links, text boxes, and various graphical elements ... then the CPU is being interrupted by the USB controller at a rate of 1500 to 6000 interrupts per second. Each of those interrupts is passed up from the BIOS to the Device driver, to the API level of the OS ... then if an event has been set up by the application software .... the interrupt is passed on up to the appropriate .Net class and the class is executed. As a programmer I have set up mouse triggers and done all kinds of nifty things with them. How the information gets from the mouse to the application program is not so hard to understand, although the number of interrupts processed per second is a little hard for me to understand.

However the real mystery to me is the graphical side of things, especially when considering that mouse cursors have been moving efficiently over the back ground graphics when graphic cards were much slower than today. I guess it is because I really don't have a grasp of how slow human hand to eye coordinated movements are compared to even the slowest CPUs and graphics adapters. .... Also the illusion of the cursor "floating" over the screen is hard to understand.
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
Early USB controllers polled the devices attached to it. That means that even if your mouse wasn't being touched, the controller still "checked up on it" fairly often (1500 to 6000 times per second, evidently).

The graphics are handled by the OS and video card. In the old days, the mouse pointer might have been a sprite controlled by the video card (hardware cursor even). There are a number of ways to draw a mouse cursor on the screen. As to it "floating" over the screen, it's just graphics ;) Look up sprites... they share a number of similar ideas with mouse cursors.
 
[url=http:/civis/viewtopic.php?p=27417177#p27417177:skwif8oi said:
Tom Dunkerton[/url]":skwif8oi]However the real mystery to me is the graphical side of things, especially when considering that mouse cursors have been moving efficiently over the back ground graphics when graphic cards were much slower than today. I guess it is because I really don't have a grasp of how slow human hand to eye coordinated movements are compared to even the slowest CPUs and graphics adapters. .... Also the illusion of the cursor "floating" over the screen is hard to understand.

I want to say (and this may just be hazy recollection) that during the early days of mice (serial), the mouse was interrupt-driven. When the mouse was moved, it would send updates to the PC of how far it had moved since the last update, and in what direction (x and y delta). The mouse driver would maintain current logical position, and change that position based on the data received from the mouse. Wikipedia has a small blurb on the serial protocol.

As for graphical updates, I'm pretty sure some systems used sprites - the mouse cursor was a sprite, the driver would update the sprite's location on mouse movent, and the video card would combine it with the contents of the framebuffer on each frame. Since the video card had to draw each frame to produce any output to the screen at all, it was an efficient way to display the mouse. The only effort the OS/driver needed to expend was to receive location updates from the mouse, and adjust the pointer location.

I know I've had computer crashes in the days of DOS/Win3.1 where the application I was using would stop, but the mouse driver would still be functioning. I could move the cursor around, but the computer was otherwise non-responsive.
 

RAOF

Ars Tribunus Militum
2,733
The hardware cursor (sprite) is a special case of overlay hardware - it comes between VRAM and the rest of the scanout hardware, modifying the signal sent to the encoder. It's the only common overlay available on desktop graphics cards, but mobile devices will often have a handful of overlays with quite sophisticated abilities - you'll often have one able to scan out of YUV buffers, able to do scaling or rotation, and alpha blending. It allows you to do fun things like display camera controls on top of a live-feed from the sensor without actually turning on the GPU.

Desktop hardware is gaining some of same stuff now, which is fun!
 
The 1500-to-6000 number is almost certainly the scanning rate of the sensor itself. Nowadays, mouse sensors are generally a VCSEL with a multi-pixel photo-sensor (basically a rudimentary camera sensor), and a dedicated DSP running motion detection on the image. The variable scan rate allows a tradeoff between detection accuracy and power usage.

If you're interested in the hardware side to get some background, google for Avago and ADNS, and check out some of the datasheets.
 
On rereading, I get the impression you might be conflating the hardware device with the sprite. The physical mouse sends information to the PC indicating it has moved some amount, but has no sense at all of where the cursor is on the screen. The OS receives messages saying saying the mouse has moved, and decides what that means, given the context of where the cursor is and how it should be behaving, according to the OS or application.

Apologies if my impression is incorrect.
 

drogin

Ars Tribunus Angusticlavius
8,283
Subscriptor++
[url=http:/civis/viewtopic.php?p=27424081#p27424081:25pe065u said:
topham[/url]":25pe065u]
[url=http:/civis/viewtopic.php?p=27424001#p27424001:25pe065u said:
SurfaceTension[/url]":25pe065u]Ball mouse? Isn't it just a couple of quadrature encoders driven by a frictional coupling?
Elegant simplicity.

The elegance only lasts until you have to start picking lint out of it with tweasers. ;)
 

Agathos

Ars Praefectus
3,558
Subscriptor
1500 to 6000 samples per second

That sounds like a lot. Back in the day, I recall a PS/2 mouse would update at something like 40 hertz. There was a program (which I think I discovered on Ars) that would let you "overclock" your mouse up to 200 hertz, which was notably smoother.

Edit: and the same option exists for USB, which defaults to 125 hertz.

https://wiki.archlinux.org/index.php/Mouse_Polling_Rate

http://blog.codinghorror.com/mouse-dpi- ... ling-rate/
 
Status
Not open for further replies.