Getting mouse button and/or keyboard events

Hi all,
I have a Windows program I am using for an experiment - I am recording
people’s reaction times in various situations, and to control the duration of
the displays people see, I increase the priority of the current process and the
current thread using the Windows functions SetPriorityClass(hProcess,
HIGH_PRIORITY_CLASS) and SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST),
respectively. Raising the priority of the current thread locks out other
Windows processes (so they don’t affect the timing of my displays), but it also
appears to lock out the keyboard and mouse, so I can’t use SDL_PollEvent() to
get mouse button presses or key presses. I’m wondering if there is another
function that will allow me to directly poll the mouse or check for specific key
presses that would not be affected by changing the priority of the thread. I
realize that this might be beyond the scope of the forum, but any information
would be helpful and appreciated. (I also realize that recording reaction times
with a mouse or keyboard event is likely to have some built-in variability; I’m
just trying to minimize that variability as much as possible). Thank you in
advance.

Chris Dickinson

Maybe:
Uint8* keystates = SDL_GetKeyState(0);

if(keystates[SDLK_SPACE])
{
// do stuff
}

and… (from docs)
SDL_PumpEvents();
if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
printf(“Mouse Button 1(left) is pressed.\n”);

Jonny D----------------------------------------

To: sdl at libsdl.org
From: dickinsonca at appstate.edu
Date: Wed, 22 Oct 2008 14:10:26 +0000
Subject: [SDL] getting mouse button and/or keyboard events

Hi all,
I have a Windows program I am using for an experiment - I am recording
people’s reaction times in various situations, and to control the duration of
the displays people see, I increase the priority of the current process and the
current thread using the Windows functions SetPriorityClass(hProcess,
HIGH_PRIORITY_CLASS) and SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST),
respectively. Raising the priority of the current thread locks out other
Windows processes (so they don’t affect the timing of my displays), but it also
appears to lock out the keyboard and mouse, so I can’t use SDL_PollEvent() to
get mouse button presses or key presses. I’m wondering if there is another
function that will allow me to directly poll the mouse or check for specific key
presses that would not be affected by changing the priority of the thread. I
realize that this might be beyond the scope of the forum, but any information
would be helpful and appreciated. (I also realize that recording reaction times
with a mouse or keyboard event is likely to have some built-in variability; I’m
just trying to minimize that variability as much as possible). Thank you in
advance.

Chris Dickinson


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008

I’ve heard of this before. As far as I know there’s no way around it. If you set your thread priority higher than that of the Windows thread that processes system interrupts, then it’ll take priority over it. If I were you, I’d find a different way to keep other processes from interfering. Do you control the testing computers that this program is running on? If so, it should be pretty simple. If not… it’ll get a bit more complicated.

Even so, in my experience it shouldn’t make much difference anyway unless the system’s running at a really high CPU load. Under normal conditions, the CPU’s running at between 3-20%, even with a bunch of programs running at once, and the experimental error introduced by all the task-switching is somewhere on the order of 16 miliseconds. Since human reaction time is measured in hundredths of a second, this is basically statistical noise. Just instruct the users to make sure that they don’t have any other programs running, and you should be fine.

Mason> ----- Original Message -----

From: dickinsonca@appstate.edu (Chris Dickinson)
To: sdl at libsdl.org
Sent: Wednesday, October 22, 2008 7:10:26 AM
Subject: [SDL] getting mouse button and/or keyboard events

Hi all,
I have a Windows program I am using for an experiment - I am recording
people’s reaction times in various situations, and to control the duration of
the displays people see, I increase the priority of the current process and the
current thread using the Windows functions SetPriorityClass(hProcess,
HIGH_PRIORITY_CLASS) and SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST),
respectively. Raising the priority of the current thread locks out other
Windows processes (so they don’t affect the timing of my displays), but it also
appears to lock out the keyboard and mouse, so I can’t use SDL_PollEvent() to
get mouse button presses or key presses. I’m wondering if there is another
function that will allow me to directly poll the mouse or check for specific key
presses that would not be affected by changing the priority of the thread. I
realize that this might be beyond the scope of the forum, but any information
would be helpful and appreciated. (I also realize that recording reaction times
with a mouse or keyboard event is likely to have some built-in variability; I’m
just trying to minimize that variability as much as possible). Thank you in
advance.

Chris Dickinson


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org