Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual path of actions happening when I press a key on keyboard and it shows on a shell?

I am using a generic usb keyboard, Linux 2.6.27 with gnome desktop, gnome-terminal and bash shell. I am interested to know what happens in the software. How are special characters from my keyboard interpreted with some encoding to characters and where do the character pictures come from?

like image 916
JtR Avatar asked Mar 13 '09 15:03

JtR


People also ask

What happens when key is pressed on keyboard?

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.

When a key is pressed a keyboard interacts with?

When a key is pressed, a keyboard interacts with : Keyboard controller.

How does the key pressed on keyboard reach the monitor?

Answer: When you press a key, it presses a switch, completing the circuit and allowing a tiny amount of current to flow through. ... When the processor finds a circuit that is closed, it compares the location of that circuit on the key matrix to the character map in its read-only memory (ROM).


1 Answers

The Linux input layer with the USB drivers gets scancodes (basically "KEY 1 DOWN" "KEY 1 UP") from the keyboard.

X uses its keymap to convert scancodes into keycodes and X input events.

The GTK input method converts the sequence of input events into composed unicode characters.

Gnome-terminal encodes these in UTF-8 for the shell.

The Shell doesn't care. it just knows that it's dealing with a multibyte encoding.

The shell echoes multibyte-encoded text back through the TTY.

Gnome-terminal decodes the incoming text and determines unicode code points.

Gnome-terminal draws characters using GTK+ facilities.

GTK+ uses Pango to render the text, and calls the X library to draw the pixels to the screen.

The X server draws characters into the screen buffer and the video card displays them.

Here is my attempt at a diagram:

alt text http://osoft.us/system_layers.png

like image 119
Joe Koberg Avatar answered Mar 30 '23 01:03

Joe Koberg