KeyListener Example

KeyListener takes three arguments: the element reference or id to attach the listener to, an object literal that contains the details about the key(s) to listen for, and the handler (represented either as a function, or a literal containing arguments for the handler function, the scope, and a scope correction flag).

KeyListeners are enabled and disabled by calling the enable() and disable() functions on a listener. The DOM events for keys are dynamically attached and detached upon enable and disable.

Press 1, 2, 3 to trigger KeyListener1.

Press Alt+Shift+(4, 5, 6, or 7) to trigger KeyListener2.