What happens from the moment we press a key on the keyboard, until it appears in your word document [closed]
开发者_开发百科
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionThis 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
- you hear a click ;) [but not necessary at this step, maybe at 10th or 20th]
- keyboard signals to kb controller
- controller issues an interrupt to CPU
- OS kernel sees interrupt
- OS kernel dispatches interrupt to corresponding driver
- driver tells CPU to read a charcode from kb controller
- CPU does
- driver some way tells the kernel to post an 'KEY_DOWN' event into UI subsystem
- kernel dispatches event
- UI subsystem checks if there active window
- 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!
精彩评论