[R] break loop with keypress
william.a.simpson at gmail.com
Wed Aug 6 11:01:40 CEST 2014
I guess another option is to call a C function directly. On Windows I
see there is a function _kbhit() in conio.h. Not sure if it would be
Write a .c file
Then do the necessary stuff to call that from R.
On 06/08/2014, Greg Snow <538280 at gmail.com> wrote:
> You could create a tcltk window that looks for a button click and/or
> key press and when that happens change the value of a variable. Then
> in your loop you just look at the value of the same variable and break
> when the value changes.
> On Tue, Aug 5, 2014 at 6:13 AM, William Simpson
> <william.a.simpson at gmail.com> wrote:
>> 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.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> Gregory (Greg) L. Snow Ph.D.
> 538280 at gmail.com
More information about the R-help