Stanislav Aggerwal
2013-Sep-30 14:46 UTC
[R] get mouse position without waiting for a click
Consider the following: par(mar=c(0,0,0,0),xaxs = 'i',yaxs='i') plot.new() for(i in 1:20) { z <- matrix(runif(256*256), ncol=256) dev.hold() image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) dev.flush() Sys.sleep(.1) } I would like to continuously display the animation until a mouse click happens. Obviously, locator() can't be used for this, because it will halt the animation while waiting for the mouse click. So something like this won't work: while((r<-locator(n=1)) == NULL) { z <- matrix(runif(256*256), ncol=256) dev.hold() image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) dev.flush() Sys.sleep(.1) } Can somebody suggest a way to get user input while displaying the animation? I am willing to use a keypress if not the mouse. Essentially, I need an input routine that does not wait for a response but just checks at one instant (like kbhit in C). Thanks very much for any help. Stan [[alternative HTML version deleted]]
On Windows or X11, (others ???) ?getGraphicsEvent Cheers, Bert On Mon, Sep 30, 2013 at 7:46 AM, Stanislav Aggerwal <stan.aggerwal at gmail.com> wrote:> Consider the following: > > par(mar=c(0,0,0,0),xaxs = 'i',yaxs='i') > plot.new() > for(i in 1:20) > { > z <- matrix(runif(256*256), ncol=256) > dev.hold() > image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) > dev.flush() > Sys.sleep(.1) > } > > I would like to continuously display the animation until a mouse click > happens. Obviously, locator() can't be used for this, because it will halt > the animation while waiting for the mouse click. So something like this > won't work: > > while((r<-locator(n=1)) == NULL) > { > z <- matrix(runif(256*256), ncol=256) > dev.hold() > image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) > dev.flush() > Sys.sleep(.1) > } > > Can somebody suggest a way to get user input while displaying the > animation? I am willing to use a keypress if not the mouse. Essentially, I > need an input routine that does not wait for a response but just checks at > one instant (like kbhit in C). > > Thanks very much for any help. > > Stan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Some code that you can look at for examples of capturing the mouse position without clicking include the playSudoku function in the sudoku package and several functions in the TeachingDemos package including HWidentify, HTKidentify, dynIdentify, and TkIdentify. On Mon, Sep 30, 2013 at 8:46 AM, Stanislav Aggerwal <stan.aggerwal@gmail.com> wrote:> Consider the following: > > par(mar=c(0,0,0,0),xaxs = 'i',yaxs='i') > plot.new() > for(i in 1:20) > { > z <- matrix(runif(256*256), ncol=256) > dev.hold() > image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) > dev.flush() > Sys.sleep(.1) > } > > I would like to continuously display the animation until a mouse click > happens. Obviously, locator() can't be used for this, because it will halt > the animation while waiting for the mouse click. So something like this > won't work: > > while((r<-locator(n=1)) == NULL) > { > z <- matrix(runif(256*256), ncol=256) > dev.hold() > image(z, col=grey(0:255/255),zlim=c(0,1),useRaster=TRUE) > dev.flush() > Sys.sleep(.1) > } > > Can somebody suggest a way to get user input while displaying the > animation? I am willing to use a keypress if not the mouse. Essentially, I > need an input routine that does not wait for a response but just checks at > one instant (like kbhit in C). > > Thanks very much for any help. > > Stan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]