r - Detecting single keystrokes -



r - Detecting single keystrokes -

several times have wanted observe single keystrokes in r have failed find else readline() or similar.

an illustration interactive plotting or info browsing , able alter parameter values arrow keys , automatically update plot. of course of study utilize readline() , have user input "u" instead of arrow don't find elegant.

could done system() command reading stdin in way?

edit: have been told elsewhere stdin wait enter-stroke before doing , catching keystrokes scheme specific , tricky accomplish. if knows how on ubuntu 10.10 or other linux/unix scheme i'd glad know.

very os-dependent solution. first c code in getkey3.c:

#include <stdio.h> #include <termios.h> #include <unistd.h> void mygetch ( int *ch ) { struct termios oldt, newt; tcgetattr ( stdin_fileno, &oldt ); newt = oldt; newt.c_lflag &= ~( icanon | echo ); tcsetattr ( stdin_fileno, tcsanow, &newt ); *ch = getchar(); tcsetattr ( stdin_fileno, tcsanow, &oldt ); return; }

compile r r cmd shlib getkey3.c

that produces getkey3.so. start r.

> dyn.load("getkey3.so") > .c("mygetch",as.integer(0))

then press key, should homecoming list first element integer value of ascii code of key. store in r variable if want.

works me on ubuntu, you're on own other oses.

barry

r

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -