Each button is an electric switch. When you press it, it sends an electrical signal. This signal might or might not get processed or modified by the circuitry in the mouse/keyboard.
That signal travels through the wire connecting your mouse or keyboard to your computer.
Whatever plug your mouse or keyboard is plugged into (say, a USB) receives that signal.
Your operating system frequently checks each of the inputs that it’s aware of to check for a signal. It notices that a signal is present and checks which signal is present.
Your operating system checks for programs that are listening for input. (Mechanically, those programs have a loop in them that says “every frame, if the user has pressed the left mouse button then…”). It then sends the input to those programs.
The programs decide what to do with the input. If it’s a word processor, for example, pressing “w” instructs it to add a “w” to the end of the data in your current document. If it’s a video game, pressing “w” might cause it to increase the vertical speed of your character. And so on.
Latest Answers