[R] break loop with keypress

William Simpson william.a.simpson at gmail.com
Tue Aug 5 14:13:38 CEST 2014

This works, but it is not quite what I need:


  dev.hold(); image(img1,useRaster=TRUE); dev.flush()
  dev.hold(); image(img2,useRaster=TRUE); dev.flush()

I would like to do this:

where kbhit() polls the keyboard, returning a non-zero integer if the
keyboard buffer has something in it. The animation loop continues
until a key is pressed.

All the ways of getting user input I have seen (e.g. getGraphicsEvent)
are not suitable because they would wait on each pass through the loop
until the key is pressed and therefore no animation would be

Any ideas on how to present a continuous animation loop which is
broken upon user input (keypress or mouse button press)? I am using
Windows 7. Thanks very much for any help.


More information about the R-help mailing list