jarreboum wrote:And why the two in the middle are never connected?
What is the function of the other two pins and why don't anyone use them?
Good question, but it goes back to IBM 5150 design.
The speaker connector in the first IBM PC was 4-pin and has been ever since.
The speaker is just connected directly to +5V and buffer output that can control current flow on and off through a 33 ohm resistor (and some low-pass filtering 10nF capacitor).
The ground is not needed for anything.
Only thing known from the manuals is that it's 2 1/4 inch and can handle about 0.5 watts.
I don't know the speaker impedance so I don't have an estimate the power rating it is being driven with.
Errius wrote:"key". That's presumably to stop you plugging it in the wrong way round. A 3 pin connector would have ambiguous orientation. Does it matter which direction the speaker current flows though?
No, speakers don't care, but the cone will move outwards or inwards depending on which way the current flows. But the emitted sound should be identical to ears in both cases even if the direction is inverted (180 degree phase shift).
It is possible that they went for keyed connector with ground so that you could later plug something to it, like an amplifier board between speaker and motherboard, and it would be sure the connector orientation is correct.
Even so, it's still convenient to have 4-pin speaker so you don't accidentally plug it into wrong place on motherboard, or plug something like front panel switches or leds to speaker connector on motherboard. That could break something.
Edit: Oh scali beat me to it, and with almost same ideas 😁