Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is a :

Key-Event Dispatcher ?

in keyboard-interactive apps.

What does it really do ?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Without more context it is hard to be sure, but usually that would be the small piece of code that receives the information "A key of the type X was just pressed/released/kept down for certain time" and then does whatever the program is supposed to to in response. (For instance, in emacs most letter keys trigger the aptly named self-insert-command, while modifier keys change the state of the program so that the next key event will do something different from the normal response.)

It can come as a surprise to beginners, but there is really no intrinsic reason why pressing an 'a' key would let a computer program react by printing an 'a' character. Programmable computers are Turing-complete machines, they can in principle give any conceivable response to any input - if you want the typewriter-like 'copying' behaviour (and in editors, shells etc. that is usually the case), the code has to be told explicitly to do it. The keyboard event dispatcher takes care of that.

share|improve this answer
add comment

it listens to all keyboard events and dispatches the events to those listeners that want it (characters to the text box, tab to the focus manager, shortcuts to the respective handler...)

this can be more efficient that everything listening to the keyboard and doing an if test, if the dispatcher uses (for example) a hash map to quickly find where to send the event

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.