[R] Getting Keypressed State in rgl

Duncan Murdoch murdoch at stats.uwo.ca
Fri Feb 29 13:16:55 CET 2008


Dieter Menne wrote:
> Dear Rglers,
>
> when using a callback in rgl (Windows, if it matters)
>
> http://finzi.psych.upenn.edu/R/library/rgl/html/callbacks.html
>
> I would like to get the Asynchronous keyboard status (as least
> Shift/Control, but preferably other key) to set markers in a plot.
>
> getGraphicsEvents seems to be limited to normal graphics windows.
>
>   
That's a general hardware problem, not really an rgl problem: you just 
want to query the keyboard.  It definitely depends on the platform.  
Windows has GetKeyState, GetKeyboardState, and GetAsyncKeyState, each 
with slightly different behaviour.   For example,

GetKeyState(VK_SHIFT);

will tell you if either shift key is down.  There are also VK_LSHIFT and 
VK_RSHIFT constants to distinguish the two shift keys.  Here's an inline 
version (untested):


isshifted <- cfunction(signature(result="integer"),
                       includes = "#include <windows.h>",
                       body = "result[0] = getKeyState(VK_SHIFT)",
                       convention = ".C")


Duncan Murdoch



More information about the R-help mailing list