Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

What Happens Inside Your Computer When a Key is Pressed?

What happens inside your computer when a key is pressed? Find out by watching this animation, narrated by Mac Bowley.
What happens in your computer when you press a key on your keyboard? First, a switch beneath the key closes, and current flows into a small chip in a keyboard. Each key has a scan code number, which corresponds to its position on the keyboard.
The keyboard transmits this number as binary data to the computer’s CPU. The CPU is running the operating system, which constantly checks for key presses. As soon as the OS detects a key press, it immediately reacts and figures out where the data needs to go. The OS knows what software was active when the key was pressed, and based on this information, creates an event. In computing, an event is an action recognised and handled by software. Events often originate from computers’ hardware. Your OS knows the layout for your keyboard. It matches the scan code to the key pressed and the associated letter, converting the scan code into a Unicode number. Your text editing software then captures the event from the operating system.
Based on the choice of font, the software converts the Unicode number into an image. The software creates a binary representation of the image and sends it back to the CPU. The CPU forwards the binary representation to the Graphics Processing Unit, or GPU. The GPU translates the binary representation into the image displayed on your monitor.
What about when keyboards have symbols in different locations? How might your operating system understand an Arabic keyboard instead of the Latin alphabet? Why not share your thoughts and join in the discussion in the comments section below.

In this step, we’re going to look at what happens when you press a key on the keyboard.

The process of pressing a key in something like Microsoft Word and seeing it displayed on the screen is a good demonstration of what a computer system is: a set of devices that input, process, output, and store data. It illustrates how the hardware on a computer communicates with the software and vice versa.

The sequence of events when you press a key is as follows.

The Key is Pressed

As the key is pressed, a switch closes and current flows into a small chip in the keyboard.

Each key on the keyboard has an associated number, called a scan code. The number is based on where the key is on the keyboard. This is useful when it comes to keyboards that have different layouts and/or symbols. This scan code is sent into the computer as a binary number.

A Number is Transmitted to the CPU

The binary data is transmitted from the keyboard to your computer.

The route the data takes will depend on how your keyboard is connected to the computer. If it’s attached by a USB cable, it will go to the USB port. If the keyboard is connected by Bluetooth, it will go to the Bluetooth receiver.

The data then travels to the brains of the computer: the CPU.

The Data is Interpreted by the Operating System

Remember, the CPU is running the operating system. The operating system is constantly checking for key presses. It may look like it’s sitting there doing nothing, but the operating system must react immediately to key presses, so it has to be ready for them all the time.

An Event is Created by the OS and Captured by Application Software

The operating system will convert the scan code into an ASCII or Unicode character based on the key pressed. You typically set the keyboard layout for your computer in the operating system, so it is the operating system that will know what letter is represented by, say, scan code 1 in this language/keyboard layout.

The OS creates an event depending on the resulting character. In computing, an event is an action that is recognised and handled by the software. It often originates from the hardware.

The OS must now send the event to the appropriate application. Many different applications are running, and the key press must be handled by the right one. The OS knows what software was active when the key was pressed, and sends the event to that application.

The application software in this example is Microsoft Word. It captures the event from the operating system.

The Application Software Displays the Character on the Screen

Microsoft Word converts the character into an image based on your font choices in Microsoft Word.

It sends this image, as a binary representation, back to the CPU, which sends it to the GPU. The GPU translates the binary code into an image and displays it on the monitor.

A lot happens when you press one key. The main devices we’re going to focus on in the next few steps are input and output devices. Can you work out which device is the input and which is the output in the scenario above? Can you work out what is hardware and what is software?

This article is from the free online

Understanding Computer Systems

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education