views:

392

answers:

3

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

+3  A: 

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!

Neurofluxation
I was once puzzled, why have they used so big holes in punch cards. The answer was amazing. The scan was not optical at all. They just used this to connect metal-to-metal switches.
Pavel Radzivilovsky
Simplicity itself!
Neurofluxation
+6  A: 
  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

zed_0xff
11 is wrong. 11 is KEY_DOWN event goes to active application, as identified by active window. Let me continue. 12. application via GetMessage() main loop gets the event and dispatches it via DispatchMessage(), probably applying some translations (that's where mapping to which window the event actually goes). 13. assigned to the window even handling routine is called and from here on it is in responsibility of application. Word processor would apply the key press to the document in memory and trigger refresh to the screen so that the new document in memory is properly reflected on the screen.
Dummy00001
+16  A: 
  • 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
Pavel Radzivilovsky
good answer. If held down after some delay the sequence repeats at a specific interval (except for the initial mechanical switch closure). When the key is released the sequence repeats again except for the switch closure which is now a switch open and you have KEYUPS instead of KEYDOWNS. In case you are asked mice operate on the button release not on the button closure, try it yourself press the mouse button over some object, move the mouse and release it over something else.
dwelch
I'm sorry, but since you did not address the fact that since with USB the host has to ask the keyboard for new data before the keyboard can be sent to the host, your answer is inadequate. Just kidding. Very good.
nategoose