\HeaderA{getGraphicsEvent}{Wait for a mouse or keyboard event from a graphics window}{getGraphicsEvent}
\keyword{iplot}{getGraphicsEvent}
\begin{Description}\relax
This function waits for input from a graphics window in the
form of a mouse or keyboard event.
\end{Description}
\begin{Usage}
\begin{verbatim}
getGraphicsEvent(prompt = "Waiting for input", 
                 onMouseDown = NULL, onMouseMove = NULL, onMouseUp = NULL, 
                 onKeybd = NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{prompt}] prompt to be displayed to the user
\item[\code{onMouseDown}] a function to respond to mouse clicks
\item[\code{onMouseMove}] a function to respond to mouse movement
\item[\code{onMouseUp}] a function to respond to mouse button releases
\item[\code{onKeybd}] a function to respond to key presses
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function allows user input from some graphics devices (currently
only the Windows screen display).  When called, event handlers may be 
installed to respond to events involving the mouse or keyboard.  

The mouse event handlers should be functions with header 
\code{function(buttons, x, y)}.  The coordinates \code{x}
and \code{y} will be passed to mouse event handlers in device independent
coordinates (i.e. the lower left corner of the window is \code{(0,0)}, 
the upper right is \code{(1,1)}).  The \code{buttons} argument 
will be a vector listing the buttons
that are pressed at the time of the event, with 0 for left, 1 for middle, and 2 
for right.

The keyboard event handler should be a function with header
\code{function(key)}.  A single element character vector will be passed
to this handler, corresponding to the key press.  Shift and other modifier
keys will have been processed, so \code{shift-a} will be passed as
\code{"A"}.  The following special keys may also be passed to the handler:
\Itemize{
\item Control keys, passed as \code{"Ctrl-A"}, etc.
\item Navigation keys, passed as one of \code{"Left", "Up", "Right", "Down",
     "PgUp", "PgDn", "End", "Home"}
\item Edit keys, passed as one of \code{"Ins", "Del"}
\item Function keys, passed as one of \code{"F1", "F2", ...}
}

The event handlers are standard R functions, and will be executed in
an environment as though they had been called directly from \code{getGraphicsEvent}.

Events will be processed until
\Itemize{
\item one of the event handlers returns
a non-\code{NULL} value which will be returned as the value of
\code{getGraphicsEvent}, or 
\item the user interrupts the function from the
console.
}
\end{Details}
\begin{Value}
A non-\code{NULL} value returned from one of the event handlers.
\end{Value}
\begin{Author}\relax
Duncan Murdoch
\end{Author}
\begin{Examples}
\begin{ExampleCode}
## Not run: 
    mousedown <- function(buttons, x, y) {
        cat("Buttons ", paste(buttons, collapse=" "), " at ", x, y, "\n")
        points(x, y)
        if (x > 0.85 && y > 0.85) "Done"
        else NULL
    }
    
    mousemove <- function(buttons, x, y) {
        points(x, y)
        NULL
    }
    
    keybd <- function(key) {
        cat("Key <", key, ">\n", sep = "")
    }
    
    plot(0:1, 0:1, type='n')
    getGraphicsEvent("Click on upper right to quit",
                     onMouseDown = mousedown,
                     onMouseMove = mousemove,
                     onKeybd = keybd)
## End(Not run)
\end{ExampleCode}
\end{Examples}

