Input

This directory contains several small samples that illustrate the input system. Each resides in a separate directory. LowLevelOverview is mostly for background. Later samples generally presume familiarity with the issues addressed by earlier ones.

Most of these samples display a view in a window so that the user can operate on it, and terminate when the user clicks in the window's close box. They use a utility class TSampleWindowProgram to do this. Displaying windows in this way is not recommended for production applications--the Document framework is preferred.

LowLevelOverview

LowLevelOverview illustrates the minimum needed to handle key input and lays bare some of the fundamental components of the inputsystem that are usually hidden. Application writers do not use the input system at this level, but might be interested to see the fundamental components of the input system in order to get a general understanding of how it works. For a typical usage example, see the KeyEventsInViews sample.

KeyEventsInViews

KeyEventsInViews illustrates how to write a simple view, TKeyInputView, that handles key events. It mixes in MSimpleEventTarget, so that events are sent to it, and MKeyEventHandler, so that MSimpleEventTarget redispatches key events to it. When a key down occurs, HandleKeyDown is called. It handles the event and returns true to stop the event from being dispatched to other targets that might be in the target chain.

KeyInteractors

KeyInteractors illustrates how to use TInteractor to direct events towards a particular MEventTarget and parse the event stream into higher-level operations on that target. It introduces TKeyInputInteractor, which examines the input stream for a sequence of key events that match a target string, and then takes special action when that sequence is encountered. TKeyInputView starts the interactor in response to a key event issued with the power key down, and from that point the interactor takes over until it matches, at which point it calls a function on TKeyInputView and restores normal event handling.

KeyBehaviors

KeyBehaviors illustrates how to attach behaviors to an MEventTarget so that the behaviors get first chance at the events. Here, a subclass of MEventTarget and MKeyEventHandler is defined, TKeyFilterBehavior, to "swallow" certain key events. When this behavior is adopted by another MEventTarget, it prevents those key events from reaching it. Here the TKeyInputView class from the previous examples is asked to adopt the behavior.

MouseEventsInViews

MouseEventsInViews is essentially the same as KeyEventsInViews, except that it uses mouse button up and down events. It illustrates how to query the mouse button state and get the event location in global coordinates.

MouseDownAndKeys

MouseDownAndKeys is a simple extension of MouseEventsInViews that shows how to specify that you want the mouse location in local rather than global coordinates, and how to find out what modifier keys were down when you receive the mouse event.

MouseEntryEvents

MouseEntryEvents illustrates how to use MouseEntered and MouseExited together with StartMouseEntryEvents to find out when the mouse enters and exits a view. Because of the overhead, mouse entry and exit events are not reported automatically for all MMouseEventHandlers.

MouseMovedEvents

MouseMovedEvents illustrates how to use MouseMoved together with StartMouseMovedEvents to track the location of a mouse in a view. Mouse-location tracking starts when the mouse enters the view, and stops when it leaves the view. Because of the overhead, mouse-moved events are not reported automatically for all MMouseEventHandlers.

MouseInteractors

MouseInteractors illustrates how to use TInteractors with mouse events. It introduces a sample interactor TPolygonInteractor and a sample view TGraphicView. The interactor is used to draw a polygon in the view. It stops when the mouse is double-clicked or the mousedown is outside the view. In the first case the polygon is closed; in the second case the polygon is erased.

InteractorChains

InteractorChains illustrates how to chain interactors. It defines a class, TClickOrDragInteractor, that is started when the mouse is clicked and that runs either of two other interactors, depending on whether the mouse is double-clicked or moved. These two interactors are generic interactors and have no special knowledge of TClickOrDragInteractor.


Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.