Thanks. If you could wrap it up in a package, provide an Rd help page with an example, and make it available on for instance CRAN, that would be even better. Then one day maybe someone else contribute with a unix version etc. Make sure to credit your sources and get the licenses right.
/Henrik On Wed, Feb 24, 2010 at 8:56 AM, Dieter Menne <dieter.me...@menne-biomed.de> wrote: > > > Dieter Menne wrote: >> >> How do I wait for a single character input without terminating "Enter"? >> > > > In case someone needs a solution for Windows, here it is. Compiled Dll from > > http://www.menne-biomed.de/download/keystate.zip > > Dieter > > #dyn.unload("keystate.dll") > dyn.load("keystate.dll") > > AsyncKeyState = function(vkey){ > state = 0 > .C("AsyncKeyState",as.integer(state),as.integer(vkey))[[1]] > } > > ShiftKeyState = function(){ > state = 0 > .C("ShiftKeyState",as.integer(state))[[1]] > } > > ControlKeyState = function(){ > state = 0 > .C("ControlKeyState",as.integer(state))[[1]] > } > > PressedKey = function(){ > state = 0 > .C("PressedKey",as.integer(state))[[1]] > } > > > # while(TRUE){ > # Sys.sleep(1) > # cat(PressedKey(),"\n") > #} > > // C Program > #include <windows.h> > #include <R.h> > //#include <Rdefines.h> > //#include <R_ext/Error.h> > > #define DLLIMPORT __declspec (dllexport) > #define VK_A 0x41 > #define VK_Z 0x5A > > DLLIMPORT void AsyncKeyState(int *state,int* vKey) { > state[0] = GetAsyncKeyState(*vKey) <0; > } > > DLLIMPORT void ControlKeyState(int *state) { > state[0] = GetAsyncKeyState(VK_CONTROL) <0; > } > > DLLIMPORT void ShiftKeyState(int *state) { > state[0] = GetAsyncKeyState(VK_SHIFT) < 0 ; > } > > DLLIMPORT void PressedKey(int *state) { > byte keyState[256]; > GetKeyboardState(keyState); > for (*state=VK_A; (*state) <= VK_Z; (*state)++) > if (keyState[*state] & 0x80) > return ; > *state = 0; > } > > > -- > View this message in context: > http://n4.nabble.com/Single-character-input-without-Enter-tp1564153p1567059.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > ______________________________________________ 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.