果冻影院

XClose

Culture Online

Home
Menu

When you type on a keyboard, how does it appear on the screen?

Wow what a great question!

Photograph of a woman typing on a macbook pro laptop.

29 March 2021

Image credit: courtesy of Unsplash.听

One evening, Finn and Gers were walking past the abandoned stately home of Ty-Pin Manor and Finn wondered if it was haunted. 听鈥淣onsense鈥, said Gers, 鈥淚鈥檒l look inside, you wait out here鈥. 听Finn didn鈥檛 think that exploring old houses in the dark was a very good idea but Gers had already gone!

Finn noticed many windows and wondered which room Gers was in. 听Gers had noticed that each room had a light switch. 听She switched one on and the light revealed many treasures. 听Gers turned off the light and tried the next room along. 听Finn realised that, as long as only one window was lit, he would always know where Gers was.
Gers wanted Finn and her other friends to see the treasures too and tried to describe the order in which she had visited the rooms. 听This was hard because the house was so big. 听鈥淚 know鈥, said Finn, 鈥渨hy don鈥檛 we put a number in each window? 听Then when you turn on the light, I can write the number down. 听When someone visits, they鈥檒l know which room you were in because the numbers will match.鈥

They drew a sketch and numbered each window. 听When Gers lit up a room, Finn wrote down its number. 听
When they had finished, they had a sequence of numbers that described precisely the order of Gers鈥 visit. 听They carefully stored the information and went home for tea.

The story of Finn and Gers illustrates what happens when a key is pressed on a keyboard. 听Each key has a switch under it. 听Pressing a key is like Gers turning on a light in Ty-Pin Manor. 听Finn could see where Gers was because electricity flowed through the light switch and lit up the bulb. 听Similarly, in your keyboard, the amount of electricity flowing through the key switch changes when pressed and the keyboard has a 鈥榙igital鈥 Finn that can see which it is.听
Notice that Finn and Gers turned Gers鈥 physical actions into information: they could represent Gers鈥 actions simply by a sequence of numbers. 听Your keyboard does something similar. 听Each key (and combination of keys) has a unique number (a scan code).听The keyboard sends the scan codes to the operating system of the computer (e.g. Windows). 听What happens after that varies a lot. 听There will probably be one or more tables that map things like the scan codes to characters (and unique numbers for those characters e.g. 鈥楢鈥 = 65, 鈥榓鈥 = 97) and map those to descriptions of the shapes that actually appear on the screen. 听We use maps because it鈥檚 easier to change a table entry than to change a whole keyboard to make a key press display something different. 听Getting the character on the screen involves (very roughly) creating a representation of the character in the appropriate place in the computer鈥檚 memory from where the graphics hardware can tell your screen what dots (pixels) to display so that we perceive a character.

In summary, to get a character on screen when you press a key, your keyboard observes which switch has been closed by the pressed key, sends the scan code for that key to the operating system, and then one or more programs use a series of maps to look up the character shape to be displayed based on the scan code. 听As with all software, there are lots of ways to achieve the same end result!