What Happens When You Press A Key
To illustrate how the computer works, let's take a very simple example. Let's suppose you are working in your word processor and you type the letter "M". Here's what happens, in general terms, when you press the "M" button:
1. The keyboard sends an electrical signal, called a scan code, to the computer saying that a button was pressed.
2. The keyboard controller interprets the scan code and determines that the letter pressed was an "M". It stores this "M" in a special memory location until the processor is ready to deal with it.
3. The controller sends a signal to the processor, called an interrupt. An interrupt tells the processor that some part of the computer has information for it to process and wants its attention. In this case, the keyboard controller wants the processor to look at the key you just pressed.
4. The processor is almost always doing many things, sharing its time among many tasks. As a result, most every event must wait its turn. The processor services interrupts based on their priority. When it is time to deal with the keypress, the processor routes it to the program for the operating system that you are using.
5. Assuming you are using a multi-tasking operating system like Windows, the operating system software decides which window you pressed the key in and sends a message to that window telling it a key was pressed.
6. The window decides what to do with the keypress. Since in this case it's your word processor window, and the key you pressed was an ordinary letter, the word processor will add that letter to its working area for the file you have open. The letter will take one byte of your computer's memory (RAM). Other keys could be handled differently (for example, if you pressed the key to tell the word processor to exit).
7. The window will then call the operating system to display the letter on the screen.
8. The operating system will display the letter on the screen by adding it to your video card's video memory.
9. The next time the video card refreshes your monitor (re-displays what is in its video memory) the letter will appear on the screen. Most video cards refresh the monitor between 60 and 100 times per second.
Wow, a lot happens even in a simple example like this! This all appears to occur instantaneously because the computer is simply operating at a much faster speed than humans can readily perceive. But despite the illusion created by the speed of the PC, a lot of activity is going on inside the box for even the most basic activity.