开发者

What happens from the moment we press a key on the keyboard, until it appears in your word document [closed]

Closed. This question is off-topic. It is not currently accepting answers.
开发者_开发百科

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

This question was in my job interview.. I just to see whether I gave all the details...


  • mechanical switch short-circuits pull up R1 resistor end to the ground
  • a special multiplexor translates it into a message, to reduce the number of wires
  • the message interpreted by a CPU embedded in the keyboard
  • message translated to a USB protocol message, and modulated as a series of electric impulses of alternating voltage between zero and 5 volts
  • USB receiving hub measures samples line voltage periodically
  • host hub controller translates the message to data
  • data enters PC thru USB bus controller, connected to PCIE bus, thru a combination of IRQ notificaitons and a DMA transfer, issued by the bus driver
  • Bus driver interprets the message and forwards it along the driver stack, ultimately to an HID driver
  • HID driver talks to windows, ultimately resulting in a window message sent to a window belonging to msword process
  • WM_KEYDOWN is translated to WM_CHAR by DefWindowProc(). While key is down, multiple WM_CHARs may be created.
  • Word application catches WM_CHAR to add another character to the document model and issue re-rendering of UI
  • UI rendering engine translates unicode codepoint to graphical image by loading respective font
  • graphics engine computes the new image of the whole area to avoid flicker, and puts it pixel-by-pixel to the screen


  1. you hear a click ;) [but not necessary at this step, maybe at 10th or 20th]
  2. keyboard signals to kb controller
  3. controller issues an interrupt to CPU
  4. OS kernel sees interrupt
  5. OS kernel dispatches interrupt to corresponding driver
  6. driver tells CPU to read a charcode from kb controller
  7. CPU does
  8. driver some way tells the kernel to post an 'KEY_DOWN' event into UI subsystem
  9. kernel dispatches event
  10. UI subsystem checks if there active window
  11. it sends a KEY_DOWN UI event to active window

... uh.. tired :) so, after that it will dispatch a key, update window contents, and call the video driver/subsystem to draw that char


Uh, if you have an old old old old binary computer: http://en.wikipedia.org/wiki/Punched_card

Then, in the time you pressed the key, you could probably make a cup of tea!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜