Pb with KbCheck

Hi,
I have a problem with a script that uses KbCheck:
The basic idea of the program is that it plays a sound, and waits for the user to give an answer by pressing a key. What happens, sometimes, and apparently randomly, is that KbCheck does not give any output while a key is pressed, and the script ends up in a infinite loop. Here is the code

KeyCode(YESresp)=0;
KeyCode(NOresp)=0;
KeyCode(EXITresp)=0;
startrt = PsychPortAudio('Start', pahandle, [], 0, 1);
while ( KeyCode(YESresp)==0 && KeyCode(NOresp)==0 && KeyCode(EXITresp)==0)
[KeyIsDown, endrt, KeyCode]=KbCheck;
WaitSecs(0.001);
end

KbCheck is initialized at the beginning of each loop.
I was wondering whether there might a priority issue between KbCheck and PsychPortAudio.


Thank you
Guillaume
--- In psychtoolbox@yahoogroups.com, "guillaume" <dalbu@...> wrote:
>
> So I have made a little progress in analyzing this issue: sometimes, the Keyboard index seems to be reassigned. Using KbChesk(-1), or using GetKeyboardIndex does not help: I have to restart Matlab to get the correct index.

A "clear PsychHID" would probably help to reenumerate the keyboard, but it will be horribly slow - unuseable for time critical keyboard checks.

This should not happen. Sounds like the system is losing its USB connection to the keyboard and reenumerates when it shows up a again. Hypothesis: This is either an operating system bug, or some loose contact / loose USB plug? Or some part of your hardware is dying, the keyboard or the computer's usb controller?

You could try if plugging a different keyboard or plugging into a different USB port helps.

good luck,
-mario




> Has anyone ever encounter such trouble?
> Guillaume
>
> --- In psychtoolbox@yahoogroups.com, "guillaume" <dalbu@> wrote:
> >
> > Hi Mario,
> > Thank you for your answer. I forgot to mention that I run this program on a Mac (G5). Nevertheless, I will try what you suggest.
> > Guillaume
> >
> > --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> > >
> > > --- In psychtoolbox@yahoogroups.com, "guillaume" <dalbu@> wrote:
> > > >
> > > > Hi,
> > > > I have a problem with a script that uses KbCheck:
> > > > The basic idea of the program is that it plays a sound, and waits for the user to give an answer by pressing a key. What happens, sometimes, and apparently randomly, is that KbCheck does not give any output while a key is pressed, and the script ends up in a infinite loop. Here is the code
> > > >
> > > > KeyCode(YESresp)=0;
> > > > KeyCode(NOresp)=0;
> > > > KeyCode(EXITresp)=0;
> > > > startrt = PsychPortAudio('Start', pahandle, [], 0, 1);
> > > > while ( KeyCode(YESresp)==0 && KeyCode(NOresp)==0 && KeyCode(EXITresp)==0)
> > > > [KeyIsDown, endrt, KeyCode]=KbCheck;
> > > > WaitSecs(0.001);
> > > > end
> > > >
> > > > KbCheck is initialized at the beginning of each loop.
> > > > I was wondering whether there might a priority issue between KbCheck and PsychPortAudio.
> > >
> > > Unlikely, but you can find out by not starting the sound playback and see if the problem persists. The WaitSecs(0.001) however, on MS-Windows, with Priority() set to a high value could cause scheduling/overload problems, although then sound should be impaired and start to stutter and glitch. WaitSecs('YieldSecs', 0.001); or even higher wait intervals might then help. MS-Windows scheduling is such a fragile thing, easy to disrupt. E.g., our KbWait functions wait about 5 msecs between polls, because given the bad timing resolution of standard keyboards, 5 or 10 msecs more or less polling induced delay really don't do any additional damage anyway.
> > >
> > > Standard procedure would be to test if our demos - most of them use KbCheck, or KbDemo do work correctly.
> > >
> > > -mario
> > >
> >
>