locator(n=1) returns the coordinates of the position of the mouse. But you have to click the left button of the mouse. How can I determine the mouse position without any click? Is it possible to extend locator in a way that locator(n=0) outputs the coordinates at once, without any click event? TclTk allows us to define very nice animations and demonstrations, see for example: demo(tkdensity). But sometimes it is much better to have output and control in one window and to be able to respond to changes of the cursor position (e.g. to that a bandwidth). Thanks! --------------------------------------------------------------------------- Peter Wolf, pwolf at wiwi.uni-bielefeld.de Department of economics, University of Bielefeld, Germany
There is nothing in the design of R base graphics to report the current position of the mouse without clicking. Indeed, the graphics model does not presume a mouse and pointer (and probably dates from the days of cross-hairs manipulated with thumb wheels), and could conceivably use a touchscreen, for example. The current graphics driver model is not really extensible either, although Paul Murrell is working on improving this. We can't add features to one or two graphical devices without changing the API and all the devices (not all of which are in the R sources). On Fri, 27 Feb 2004, Peter Wolf wrote:> locator(n=1) returns the coordinates of the position of the mouse. > But you have to click the left button of the mouse. > How can I determine the mouse position without any click? > Is it possible to extend locator in a way that > locator(n=0) outputs the coordinates at once, without any click event? > > TclTk allows us to define very nice animations and demonstrations, > see for example: demo(tkdensity). But sometimes it is much better > to have output and control in one window and to be able to respond > to changes of the cursor position (e.g. to that a bandwidth).But Tcl/Tk is a different sort of system, designed for interactive windows not plotting graphs. You could do all this in Tcl/Tk (and there is no reason not to have an R graphics device in a Tcl/Tk canvas), or in a Java-based graphics device. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Peter Wolf wrote:> locator(n=1) returns the coordinates of the position of the mouse. > But you have to click the left button of the mouse. > How can I determine the mouse position without any click? > Is it possible to extend locator in a way that locator(n=0) outputs the > coordinates at once, without any click event? >I just took twenty minutes to bash devX11.c newX11_Locator routine into using XQueryPointer instead of waiting for a mouse event. That breaks the 'click to enter point' behaviour though. I couldn't figure out how to quickly modify things to just do this for n=0. I cant do everything in the twenty mins before morning tea break. Its a gross hack, and as Brian says, there's nothing in the design that lets you do this, but then since you have the source there's nothing on the planet to stop you doing this. The design is not a law :) The beauty of open-source code eh? If you really want to do this its quite easy. Mail me for more details. Baz
Peter, On Fri, Feb 27, 2004 at 10:16:54AM +0100, Peter Wolf wrote:> locator(n=1) returns the coordinates of the position of the mouse. > But you have to click the left button of the mouse. > How can I determine the mouse position without any click? > Is it possible to extend locator in a way that > locator(n=0) outputs the coordinates at once, without any click event? > > TclTk allows us to define very nice animations and demonstrations, > see for example: demo(tkdensity). But sometimes it is much better > to have output and control in one window and to be able to respond > to changes of the cursor position (e.g. to that a bandwidth).James Wettenhall has an example of how to do that using tcltk. The window manager gives us back x,y pixel coordinates, which can be converted back to plot coordinates using par("usr") and par("plt") -- it's pretty much all there on James' example page at http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/InteractiveTkrPlot.html Hth, Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page