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

对着背影说爱祢 提交于 2019-12-03 09:17:22

问题


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


回答1:


  • 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



回答2:


  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




回答3:


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!



来源:https://stackoverflow.com/questions/3083378/what-happens-from-the-moment-we-press-a-key-on-the-keyboard-until-it-appears-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!