This question was in my job interview.. I just to see whether I gave all the details...
views:
392answers:
3
+4
Q:
What happens from the moment we press a key on the keyboard, until it appears in your word document
+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
2010-06-21 09:22:59
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
2010-06-21 09:44:18
Simplicity itself!
Neurofluxation
2010-06-21 09:52:36
+6
A:
- 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
zed_0xff
2010-06-21 09:24:49
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
2010-06-21 09:32:48
+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
2010-06-21 09:29:06
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
2010-06-21 14:36:59
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
2010-06-21 21:27:26