mouse(4)

✨ mouse β€” like, the whole serial mouse interface πŸ’–

okay bestie, sit DOWN, because we're about to talk about mouse(4), aka the serial mouse interface, and it is lowkey iconic. this is a section 4 kernel interfaces manual page, so it's giving "device driver lore" energy, and we are going to read every single byte of it together. grab a snack. πŸ“


🌸 CONFIGURATION 🌸

Serial mice plug into a serial RS232/V24 dialout line, bestie. that's it, that's the config. if you need the whole rundown on that serial line situation, go check ttyS(4) β€” it has the description you're looking for. 🫢


✨ DESCRIPTION ✨

πŸ‘‘ Introduction

okay so first things first: the pinout. the plug we're talking about is the usual 9 pin plug that serial mice use, and here's the whole vibe:

                       pin   name   used for
                         2    RX    Data
                         3    TX    -12 V, Imax = 10 mA
                         4   DTR    +12 V, Imax = 10 mA
                         7   RTS    +12 V, Imax = 10 mA
                         5   GND    Ground
that's the specification, bestie. in practice, 9 V suffices with most mice. not me fact-checking the spec with reality but here we are πŸ’€

so how does the driver even know a mouse is there? the way that it can recognize a mouse is by dropping RTS to low and raising it again. about 14 ms later the mouse will send 0x4D ('M') on the data line. and then, after a further 63 ms? a Microsoft-compatible 3-button mouse will send 0x33 ('3'). it's literally saying hi. iconic behavior. πŸŽ€

the relative mouse movement gets sent as dx (positive means right) and dy (positive means down). various mice can operate at different speeds, so to select speeds you cycle through the speeds 9600, 4800, 2400, and 1200 bit/s β€” each time writing the two characters from the table below and waiting 0.1 seconds. here's the speeds and the strings that select them:

                                bit/s   string
                                9600    *q
                                4800    *p
                                2400    *o
                                1200    *n

and pro tip (well, the manpage's tip, i'm not inventing anything): the first byte of a data packet can be used for synchronization purposes. slay. ⭐

πŸ¦‹ Microsoft protocol

The Microsoft protocol uses 1 start bit, 7 data bits, no parity and one stop bit at the speed of 1200 bits/sec. Data is sent to RxD in 3-byte packets. The dx and dy movements are sent as two's-complement, lb (rb) are set when the left (right) button is pressed:

                    byte   d6   d5    d4    d3    d2    d1    d0
                       1   1    lb    rb    dy7   dy6   dx7   dx6
                       2   0    dx5   dx4   dx3   dx2   dx1   dx0
                       3   0    dy5   dy4   dy3   dy2   dy1   dy0

πŸŽ€ 3-button Microsoft protocol

Original Microsoft mice only have two buttons. BUT β€” and this is the plot twist β€” there are some three button mice which also use the Microsoft protocol. pressing or releasing the middle button is reported by sending a packet with zero movement and no buttons pressed.

thus, unlike for the other two buttons, the status of the middle button is not reported in each packet. so if you were expecting middle-button status in every single packet… no. it simply doesn't do that. πŸ’…

🧚 Logitech protocol

Logitech serial 3-button mice use a different extension of the Microsoft protocol: when the middle button is up, the above 3-byte packet is sent. when the middle button is down, a 4-byte packet is sent, where the 4th byte has value 0x20 (or at least has the 0x20 bit set). in particular, a press of the middle button is reported as 0,0,0,0x20 when no other buttons are down. obsessed with the specificity honestly.

πŸ’œ Mousesystems protocol

the Mousesystems protocol uses 1 start bit, 8 data bits, no parity, and two stop bits at the speed of 1200 bits/sec. Data is sent to RxD in 5-byte packets. dx is sent as the sum of the two two's-complement values, dy is send as negated sum of the two two's-complement values. lb (mb, rb) are cleared when the left (middle, right) button is pressed:

          byte   d7    d6     d5     d4     d3     d2     d1     d0
             1   1     0      0      0      0      lb     mb     rb
             2   0    dxa6   dxa5   dxa4   dxa3   dxa2   dxa1   dxa0
             3   0    dya6   dya5   dya4   dya3   dya2   dya1   dya0
             4   0    dxb6   dxb5   dxb4   dxb3   dxb2   dxb1   dxb0
             5   0    dyb6   dyb5   dyb4   dyb3   dyb2   dyb1   dyb0

bytes 4 and 5 describe the change that occurred since bytes 2 and 3 were transmitted. so it's like, the ✨delta after the delta✨. iykyk. 🌈

🌸 Sun protocol

the Sun protocol is the 3-byte version of the above 5-byte Mousesystems protocol: the last two bytes are not sent. short and sweet, we love a minimal queen. πŸ‘‘

πŸ’– MM protocol

the MM protocol uses 1 start bit, 8 data bits, odd parity, and one stop bit at the speed of 1200 bits/sec. Data is sent to RxD in 3-byte packets. dx and dy are sent as single signed values, the sign bit indicating a negative value. lb (mb, rb) are set when the left (middle, right) button is pressed:

             byte   d7   d6    d5    d4    d3    d2    d1    d0
                1   1     0     0    dxs   dys   lb    mb    rb
                2   0    dx6   dx5   dx4   dx3   dx2   dx1   dx0
                3   0    dy6   dy5   dy4   dy3   dy2   dy1   dy0

🫢 FILES 🫢

  • /dev/mouse β€” a commonly used symbolic link pointing to a mouse device. that's the one you'll see in the wild fr fr. 🐭

⭐ SEE ALSO ⭐


okay that's the whole page, bestie, you ate that. πŸ’… and for the little archive moment at the bottom: this one's from the Linux man-pages 6.20, dated 2025-05-17 β€” so now you know exactly which version of the lore you just learned. no cap, go read a serial port. πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms