What happens after a user presses a key?

Write a step by step execution of things that happen after a user presses a key on the keyboard. Use as much detail as possible.

My initial thoughts:

  1. A key is pressed, which triggers a signal and that is transferred to the computer.
  2. That triggers an event (exception). The OS need to handle it.
  3. The OS maps the key to a keycode according to the key map.
  4. Appropriate functions will be executed according to the keycode


  1. The keyboard sends a scan code of the key to the keyboard controller (Scan code for key pressed and key released is different).
  2. The keyboard controller interprets the scan code and stores it in a buffer.
  3. The keyboard controller sends a hardware interrupt to the processor. This is done by putting signal on “interrupt request line”: IRQ 1.
  4. The interrupt controller maps IRQ 1 into INT 9.
  5. An interrupt is a signal which tells the processor to stop what it was doing currently and do some special task.
  6. The processor invokes the “Interrupt handler”. CPU fetches the address of “Interrupt Service Routine” (ISR) from “Interrupt Vector Table” maintained by the OS (Processor use the IRQ number for this)
  7. The ISR reads the scan code from port 60h and decides whether to process it or pass the control to program for taking action.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: