Mouse hardware programming

There are basically three different ways in which a mouse can be connected to a PC: Via a special interface card (a 'bus mouse'), via a PS/2 style connection (a 'PS/2 mouse') and via the serial port (a 'serial mouse'). All operate in basically the same way: Data packets containing information about mouse movement (measured in units of 'mickeys') and button press states are sent to the PC whenever the mouse moves or the button press state changes.

I have no info on programming PS/2 or bus mice. Anything that anyone has would be appreciated.

Contents:

Introduction

Serial mice are connected to the serial port of a PC and use the RS-232-C protocol (supported by the PC's serial hardware) to send information to the PC.

Originally mice pretty much always used one of the two protocols, Microsoft Mode (for 2 button mice) and Mouse Systems Mode (for 3 button mice). The names come from the respective companies which (presumably) defined the standards in the first place.

Now, three button mice generally support both protocols; Switching between them is either done manually with a switch on the actual mouse hardware, or by the use of a serial control line. The DTR and RTS lines are both set active for normal operation; one or the other controls mode switching (the other line is used as a power supply for the mouse). The details depends on the model and manufacturer of the mouse (though they can be determined by trial and error for any particular mouse).

Autodetecting the mouse type is possible because serial mice send an identification byte immediately after they are powered on (by raising the appropriate control line[s]). See the description of the protocol for the identification bytes of each protocol. Identification should generally be performed using a 7-data-bit transfer protocol (no parity, 1 stop bit).

Author's note: I have a mouse which uses the DTR line as the switch (active = microsoft mode) and the RTS as power supply. If there are really variations on this, i'd like to know.

Microsoft Mode

The MSB of first byte is used as synchronisation failure protection (so driver software stays in sync with hardware). X7-0 are the X delta value (that is, the amount of movement since the last packet was sent), Y7-0 are the Y delta, LB = left button state (1=pushed), RB = right button state.

The Microsoft Ballpoint pointing device

I'm not exactly sure what this is (some kind of mouse or trackball presumably) but the programming information is here. It appears to have four buttons (switches) named "sw1" through "sw4".

Mouse Systems Mode

Unlike the Microsoft Mode, LB/MB/RB are 0 if pushed, 1 if not. The delta values X' and Y' give the movement since the X and Y values (in the same packet) were sent. Driver/hardware synchronisation is not as easy as for Microsoft Mode; the only real test is that the first byte bits match those shown above. A far better test is to measure the delay between bytes being recieved; there should be no long delays in the middle of a packet. As long as the driver is guarenteed to recive all bytes sent, however, there should be no problem as transmission should be reliable.