[R] Single character input without Enter
Dieter Menne
dieter.menne at menne-biomed.de
Wed Feb 24 08:56:31 CET 2010
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.
More information about the R-help
mailing list