What happens from the moment we press a key on the

2020-05-23 08:27发布

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

3条回答
家丑人穷心不美
2楼-- · 2020-05-23 09:07

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!

查看更多
Lonely孤独者°
3楼-- · 2020-05-23 09:13
  • 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
查看更多
女痞
4楼-- · 2020-05-23 09:24
  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

查看更多
登录 后发表回答