
The innards of a keyboard
Conceptually a keyboard is a collection of 100 or so individual switches all connected to a circuit that continuously senses their state and reports any change to the connected computer. You press a key, a message is sent with the key’s numeric code and the fact it was pressed. You release it, another message is sent.
Nowadays the common way to transfer these messages is through USB.