What is a :
Key-Event Dispatcher ?
in keyboard-interactive apps.
What does it really do ?
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.
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