Re: [R] Getting Keypressed State in rgl

From: Duncan Murdoch <>
Date: Fri, 29 Feb 2008 09:15:48 -0500

On 2/29/2008 7:16 AM, Duncan Murdoch wrote:
> Dieter Menne wrote:

>> Dear Rglers,
>> when using a callback in rgl (Windows, if it matters)
>> 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

Now I'm on Windows, I can see that doesn't work. Here's a version that almost does:

isshifted <- cfunction( includes = "#include <windows.h>",

              body = "return ScalarInteger(GetKeyState(VK_SHIFT));")

The problem with this one is that it puts "#include <R.h>" ahead of "#include <windows.h>", and that causes a compile error because of a clash in the use of names.

If you edit the generated source you can fix this, but I suppose cfunction should allow you to put the windows include first, and I suppose R should try to avoid clashing with it.

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 29 Feb 2008 - 14:17:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Feb 2008 - 14:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive