continuous registering responses with KbCheck

Hello List,

I'd like to have responses recorded continuously while various stimuli
are being presented (by recorded I mean (1) the key that was pressed
and (2) the 'reaction time' from trial onset). There is no constraint
as to when the participant is to respond (hence before, during or
after each stimulus is valid). Each trial can be as long as 5 minutes.

I am putting an excerpt of the script below. This is not currently
doing the job. I have tried a couple different ways but somehow I
never get the full set of responses. (i.e. if I test myself and press
10 times a key during the period, only 2 of them might be recorded).

I have tried to change the position of the KbCheck in and out of the
loop, create a timing loop before and including the trial
presentation...I am sure there is a very simple way to do this, but I
can't seem to find it....

Any help would be most appreciated!! Thanks in advance!

(System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)


Actual Trial loop:

%%%%%%%%%%%
for i = 1:length(condOrder)

Screen('FillRect',w, black);
drawFixation(FIX_COLOR);
Screen('Flip', w);

if condOrder(i) == 1
deviant = deviantC1;
devname = 'deviantC1';
[...]
else
deviant = deviantD3;
devname = 'deviantD3';
end

% ----- initialization variables ------
idx = 1;
j = 0;

rtime = [];
keyPresses=[];
keyTimes =[];
devTimes = [];

tic;
iterations = 20;
numdeviants = 3;

% randomly determine timing of deviants
tmp = Shuffle(1:5:iterations);
j_rnd = sort(tmp(1:numdeviants));
% ----- end initialization variables ------


k = j_rnd(idx);

TrialTime = GetSecs;


while j <= iterations
k = j_rnd(idx);

[keyIsDown,secs,keyCode]= KbCheck();
keyNumber = getKeyNumber(keyCode); % get numerical value

if ~ isempty(keyNumber)
keyPresses = [keyPresses keyNumber];
keyTimes= [keyTimes secs];
end

if j == k
devTime = GetSecs;
devTimes = [devTimes devTime];

sound (deviant,fs);
idx = idx + 1;

if idx > length(j_rnd)
idx = 1;
end
else
sound(triplet,fs);
end %if

j=j+1;

end %while j
endtime = clock;


%%% sub-function, end of script
%--------------------------------------------------------------------------
function keyNumber = getKeyNumber( keyCode )
global ESC_KEY
keyNumber=[];
for i=1:length(keyCode)
if keyCode(i)
keyName=upper(KbName(i)); %get the key name from the
keyboard key index
if strcmp(keyName, ESC_KEY)
error('ESCAPE key detected');
end
keyNumber=str2num(keyName); %turn the key name into a number
return; %return once the first key pressed is found
end
end
%--------------------------------------------------------------------------
Hi,

My experience with getting multiple keys all at once
was that there is a limit in keyboard input. This
depends on the keys that you choose. if the keys that
you choose are in two different rows(2 in one and 2 in
the other row like: a,z,k,m) never the four and usualy
just two of the keypresses are recorded. But when you
choose the keys so that all of them are in one row
like: z,x,m,n (I have tested up to 4 keys I do not
know about more) all of them will be recorded. I do
not know exactly what is the technical problem with
the keyboard but this is what I found by experiment.

Hope it is helpull,
Bests,
Maryam.

--- vvanwass <vvanwass@...> wrote:

> Hello List,
>
> I'd like to have responses recorded continuously
> while various stimuli
> are being presented (by recorded I mean (1) the key
> that was pressed
> and (2) the 'reaction time' from trial onset). There
> is no constraint
> as to when the participant is to respond (hence
> before, during or
> after each stimulus is valid). Each trial can be as
> long as 5 minutes.
>
> I am putting an excerpt of the script below. This is
> not currently
> doing the job. I have tried a couple different ways
> but somehow I
> never get the full set of responses. (i.e. if I test
> myself and press
> 10 times a key during the period, only 2 of them
> might be recorded).
>
> I have tried to change the position of the KbCheck
> in and out of the
> loop, create a timing loop before and including the
> trial
> presentation...I am sure there is a very simple way
> to do this, but I
> can't seem to find it....
>
> Any help would be most appreciated!! Thanks in
> advance!
>
> (System: G5, Matlab 7.0.4 and either PsychToolboz
> v1.0.5 or v1.0.6)
>
>
> Actual Trial loop:
>
> %%%%%%%%%%%
> for i = 1:length(condOrder)
>
> Screen('FillRect',w, black);
> drawFixation(FIX_COLOR);
> Screen('Flip', w);
>
> if condOrder(i) == 1
> deviant = deviantC1;
> devname = 'deviantC1';
> [...]
> else
> deviant = deviantD3;
> devname = 'deviantD3';
> end
>
> % ----- initialization variables ------
> idx = 1;
> j = 0;
>
> rtime = [];
> keyPresses=[];
> keyTimes =[];
> devTimes = [];
>
> tic;
> iterations = 20;
> numdeviants = 3;
>
> % randomly determine timing of deviants
> tmp = Shuffle(1:5:iterations);
> j_rnd = sort(tmp(1:numdeviants));
> % ----- end initialization variables ------
>
>
> k = j_rnd(idx);
>
> TrialTime = GetSecs;
>
>
> while j <= iterations
> k = j_rnd(idx);
>
> [keyIsDown,secs,keyCode]= KbCheck();
> keyNumber = getKeyNumber(keyCode); %
> get numerical value
>
> if ~ isempty(keyNumber)
> keyPresses = [keyPresses keyNumber];
> keyTimes= [keyTimes secs];
> end
>
> if j == k
> devTime = GetSecs;
> devTimes = [devTimes devTime];
>
> sound (deviant,fs);
> idx = idx + 1;
>
> if idx > length(j_rnd)
> idx = 1;
> end
> else
> sound(triplet,fs);
> end %if
>
> j=j+1;
>
> end %while j
> endtime = clock;
>
>
> %%% sub-function, end of script
>
%--------------------------------------------------------------------------
> function keyNumber = getKeyNumber( keyCode )
> global ESC_KEY
> keyNumber=[];
> for i=1:length(keyCode)
> if keyCode(i)
> keyName=upper(KbName(i)); %get the key
> name from the
> keyboard key index
> if strcmp(keyName, ESC_KEY)
> error('ESCAPE key detected');
> end
> keyNumber=str2num(keyName); %turn the
> key name into a number
> return; %return once the first key
> pressed is found
> end
> end
>
%--------------------------------------------------------------------------
>
>
>
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Hi Maryam,

thanks for your input. The keys are either '1' or '2' on the num keypad. They are thus 'aligned'.

Thanks,
Virginie

maryam vaziri-pashkam <mvaziri_p@...> wrote:
Hi,

My experience with getting multiple keys all at once
was that there is a limit in keyboard input. This
depends on the keys that you choose. if the keys that
you choose are in two different rows(2 in one and 2 in
the other row like: a,z,k,m) never the four and usualy
just two of the keypresses are recorded. But when you
choose the keys so that all of them are in one row
like: z,x,m,n (I have tested up to 4 keys I do not
know about more) all of them will be recorded. I do
not know exactly what is the technical problem with
the keyboard but this is what I found by experiment.

Hope it is helpull,
Bests,
Maryam.

--- vvanwass <vvanwass@yahoo. com> wrote:

> Hello List,
>
> I'd like to have responses recorded continuously
> while various stimuli
> are being presented (by recorded I mean (1) the key
> that was pressed
> and (2) the 'reaction time' from trial onset). There
> is no constraint
> as to when the participant is to respond (hence
> before, during or
> after each stimulus is valid). Each trial can be as
> long as 5 minutes.
>
> I am putting an excerpt of the script below. This is
> not currently
> doing the job. I have tried a couple different ways
> but somehow I
> never get the full set of responses. (i.e. if I test
> myself and press
> 10 times a key during the period, only 2 of them
> might be recorded).
>
> I have tried to change the position of the KbCheck
> in and out of the
> loop, create a timing loop before and including the
> trial
> presentation. ..I am sure there is a very simple way
> to do this, but I
> can't seem to find it....
>
> Any help would be most appreciated! ! Thanks in
> advance!
>
> (System: G5, Matlab 7.0.4 and either PsychToolboz
> v1.0.5 or v1.0.6)
>
>
> Actual Trial loop:
>
> %%%%%%%%%%%
> for i = 1:length(condOrder)
>
> Screen('FillRect' ,w, black);
> drawFixation( FIX_COLOR) ;
> Screen('Flip' , w);
>
> if condOrder(i) == 1
> deviant = deviantC1;
> devname = 'deviantC1';
> [...]
> else
> deviant = deviantD3;
> devname = 'deviantD3';
> end
>
> % ----- initialization variables ------
> idx = 1;
> j = 0;
>
> rtime = [];
> keyPresses=[ ];
> keyTimes =[];
> devTimes = [];
>
> tic;
> iterations = 20;
> numdeviants = 3;
>
> % randomly determine timing of deviants
> tmp = Shuffle(1:5: iterations) ;
> j_rnd = sort(tmp(1:numdevia nts));
> % ----- end initialization variables ------
>
>
> k = j_rnd(idx);
>
> TrialTime = GetSecs;
>
>
> while j <= iterations
> k = j_rnd(idx);
>
> [keyIsDown,secs, keyCode]= KbCheck();
> keyNumber = getKeyNumber( keyCode); %
> get numerical value
>
> if ~ isempty(keyNumber)
> keyPresses = [keyPresses keyNumber];
> keyTimes= [keyTimes secs];
> end
>
> if j == k
> devTime = GetSecs;
> devTimes = [devTimes devTime];
>
> sound (deviant,fs) ;
> idx = idx + 1;
>
> if idx > length(j_rnd)
> idx = 1;
> end
> else
> sound(triplet, fs);
> end %if
>
> j=j+1;
>
> end %while j
> endtime = clock;
>
>
> %%% sub-function, end of script
>
%----------- --------- --------- --------- --------- --------- --
> function keyNumber = getKeyNumber( keyCode )
> global ESC_KEY
> keyNumber=[] ;
> for i=1:length(keyCode)
> if keyCode(i)
> keyName=upper( KbName(i) ); %get the key
> name from the
> keyboard key index
> if strcmp(keyName, ESC_KEY)
> error('ESCAPE key detected');
> end
> keyNumber=str2num( keyName); %turn the
> key name into a number
> return; %return once the first key
> pressed is found
> end
> end
>
%----------- --------- --------- --------- --------- --------- --
>
>
>
>
>

____________ _________ _________ _________ _________ __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail. yahoo.com


Get your email and more, right on the new Yahoo.com

Dear Virginie,

This seems like the problem then. You will need to have another loop within your iteration that continually calls KbCheck, with a waitsecs(0.001) also to ensure that the CPU isn't overloaded.

I'd suggest something like this:

exit_time = GetSecs + iteration_duration;
while(GetSecs < exit_time)
[keyisdown, secs, keycode] = KbCheck;
if keyisdown
break
end
waitsecs(0.001)
end

This will continually poll your keyboard, breaking out of the loop once a key is pressed, or exiting when the specified duration has elapsed. You can do other things if you need to within the loop as well.

keith

On Aug 29, 2006, at 1:30 PM, Virginie van Wassenhove wrote:

Dear Keith,

yes this is in fact an issue. I have tried to use the KbCheck within the 'if' statement (in addition to within the 'while') or create another 'while' statement for the KbCheck before the while pertaining to the iteration. None of these two worked.

Each iteration is ~550ms but can vary with stimulus length, no longer than 1s -I don't expect to have multiple key presses during that time.

Thanks,
Virginie
Keith Schneider <ks@...> wrote:
Dear Vvanwass,

Looking at your script briefly, it looks like you are polling the
keyboard only once per "iteration". How long is each iteration? You
should be polling the keyboard every few milliseconds at least.
Remember, the KbCheck function only tells you whether a key is
depressed at the instant that the function is called.

keith

On Aug 29, 2006, at 1:01 PM, vvanwass wrote:

> Hello List,
>
> I'd like to have responses recorded continuously while various stimuli
> are being presented (by recorded I mean (1) the key that was pressed
> and (2) the 'reaction time' from trial onset). There is no constraint
> as to when the participant is to respond (hence before, during or
> after each stimulus is valid). Each trial can be as long as 5 minutes.
>
> I am putting an excerpt of the script below. This is not currently
> doing the job. I have tried a couple different ways but somehow I
> never get the full set of responses. (i.e. if I test myself and press
> 10 times a key during the period, only 2 of them might be recorded).
>
> I have tried to change the position of the KbCheck in and out of the
> loop, create a timing loop before and including the trial
> presentation. ..I am sure there is a very simple way to do this, but I
> can't seem to find it....
>
> Any help would be most appreciated! ! Thanks in advance!
>
> (System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
>
>
> Actual Trial loop:
>
> %%%%%%%%%%%
> for i = 1:length(condOrder)
>
> Screen('FillRect' ,w, black);
> drawFixation( FIX_COLOR) ;
> Screen('Flip' , w);
>
> if condOrder(i) == 1
> deviant = deviantC1;
> devname = 'deviantC1';
> [...]
> else
> deviant = deviantD3;
> devname = 'deviantD3';
> end
>
> % ----- initialization variables ------
> idx = 1;
> j = 0;
>
> rtime = [];
> keyPresses=[ ];
> keyTimes =[];
> devTimes = [];
>
> tic;
> iterations = 20;
> numdeviants = 3;
>
> % randomly determine timing of deviants
> tmp = Shuffle(1:5: iterations) ;
> j_rnd = sort(tmp(1:numdevia nts));
> % ----- end initialization variables ------
>
>
> k = j_rnd(idx);
>
> TrialTime = GetSecs;
>
>
> while j <= iterations
> k = j_rnd(idx);
>
> [keyIsDown,secs, keyCode]= KbCheck();
> keyNumber = getKeyNumber( keyCode); % get numerical value
>
> if ~ isempty(keyNumber)
> keyPresses = [keyPresses keyNumber];
> keyTimes= [keyTimes secs];
> end
>
> if j == k
> devTime = GetSecs;
> devTimes = [devTimes devTime];
>
> sound (deviant,fs) ;
> idx = idx + 1;
>
> if idx > length(j_rnd)
> idx = 1;
> end
> else
> sound(triplet, fs);
> end %if
>
> j=j+1;
>
> end %while j
> endtime = clock;
>
>
> %%% sub-function, end of script
> %----------- --------- --------- --------- --------- --------- --
> ----
> function keyNumber = getKeyNumber( keyCode )
> global ESC_KEY
> keyNumber=[] ;
> for i=1:length(keyCode)
> if keyCode(i)
> keyName=upper( KbName(i) ); %get the key name from the
> keyboard key index
> if strcmp(keyName, ESC_KEY)
> error('ESCAPE key detected');
> end
> keyNumber=str2num( keyName); %turn the key name into a
> number
> return; %return once the first key pressed is found
> end
> end
> %----------- --------- --------- --------- --------- --------- --
> ----
>
>
>
>
>
>
> Post your message to: psychtoolbox@ yahoogroups. com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox .org
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>




Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.

Hi Keith,

thanks for the code snippet. I have tried to implement it (within the iteration loop) but it is still not stable. It seems that a WaitSecs of 1ms is too short -i.e. it does not seem to flush out the previous keypresses - and 10 to 100ms either partially reports the key presses, not at all, or too many....
I'll try and work around these things some more

Thanks again!
Virginie

Keith Schneider <ks@...> wrote:
Dear Virginie,

This seems like the problem then.  You will need to have another loop within your iteration that continually calls KbCheck, with a waitsecs(0.001) also to ensure that the CPU isn't overloaded.

I'd suggest something like this:

exit_time = GetSecs + iteration_duration;
while(GetSecs < exit_time)
   [keyisdown, secs, keycode] = KbCheck;
   if keyisdown
    break
  end
  waitsecs(0.001)
end

This will continually poll your keyboard, breaking out of the loop once a key is pressed, or exiting when the specified duration has elapsed.  You can do other things if you need to within the loop as well.

keith

On Aug 29, 2006, at 1:30 PM, Virginie van Wassenhove wrote:

Dear Keith,

yes this is in fact an issue. I have tried to use the KbCheck within the 'if' statement (in addition to within the 'while') or create another 'while' statement for the KbCheck before the while pertaining to the iteration. None of these two worked.

Each iteration is ~550ms but can vary with stimulus length, no longer than 1s -I don't expect to have multiple key presses during that time.

Thanks,
Virginie
Keith Schneider <ks@.... edu> wrote:
Dear Vvanwass,

Looking at your script briefly, it looks like you are polling the
keyboard only once per "iteration". How long is each iteration? You
should be polling the keyboard every few milliseconds at least.
Remember, the KbCheck function only tells you whether a key is
depressed at the instant that the function is called.

keith

On Aug 29, 2006, at 1:01 PM, vvanwass wrote:

> Hello List,
>
> I'd like to have responses recorded continuously while various stimuli
> are being presented (by recorded I mean (1) the key that was pressed
> and (2) the 'reaction time' from trial onset). There is no constraint
> as to when the participant is to respond (hence before, during or
> after each stimulus is valid). Each trial can be as long as 5 minutes.
>
> I am putting an excerpt of the script below. This is not currently
> doing the job. I have tried a couple different ways but somehow I
> never get the full set of responses. (i.e. if I test myself and press
> 10 times a key during the period, only 2 of them might be recorded).
>
> I have tried to change the position of the KbCheck in and out of the
> loop, create a timing loop before and including the trial
> presentation. ..I am sure there is a very simple way to do this, but I
> can't seem to find it....
>
> Any help would be most appreciated! ! Thanks in advance!
>
> (System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
>
>
> Actual Trial loop:
>
> %%%%%%%%%%%
> for i = 1:length(condOrder)
>
> Screen('FillRect' ,w, black);
> drawFixation( FIX_COLOR) ;
> Screen('Flip' , w);
>
> if condOrder(i) == 1
> deviant = deviantC1;
> devname = 'deviantC1';
> [...]
> else
> deviant = deviantD3;
> devname = 'deviantD3';
> end
>
> % ----- initialization variables ------
> idx = 1;
> j = 0;
>
> rtime = [];
> keyPresses=[ ];
> keyTimes =[];
> devTimes = [];
>
> tic;
> iterations = 20;
> numdeviants = 3;
>
> % randomly determine timing of deviants
> tmp = Shuffle(1:5: iterations) ;
> j_rnd = sort(tmp(1:numdevia nts));
> % ----- end initialization variables ------
>
>
> k = j_rnd(idx);
>
> TrialTime = GetSecs;
>
>
> while j <= iterations
> k = j_rnd(idx);
>
> [keyIsDown,secs, keyCode]= KbCheck();
> keyNumber = getKeyNumber( keyCode); % get numerical value
>
> if ~ isempty(keyNumber)
> keyPresses = [keyPresses keyNumber];
> keyTimes= [keyTimes secs];
> end
>
> if j == k
> devTime = GetSecs;
> devTimes = [devTimes devTime];
>
> sound (deviant,fs) ;
> idx = idx + 1;
>
> if idx > length(j_rnd)
> idx = 1;
> end
> else
> sound(triplet, fs);
> end %if
>
> j=j+1;
>
> end %while j
> endtime = clock;
>
>
> %%% sub-function, end of script
> %----------- --------- --------- --------- --------- --------- --
> ----
> function keyNumber = getKeyNumber( keyCode )
> global ESC_KEY
> keyNumber=[] ;
> for i=1:length(keyCode)
> if keyCode(i)
> keyName=upper( KbName(i) ); %get the key name from the
> keyboard key index
> if strcmp(keyName, ESC_KEY)
> error('ESCAPE key detected');
> end
> keyNumber=str2num( keyName); %turn the key name into a
> number
> return; %return once the first key pressed is found
> end
> end
> %----------- --------- --------- --------- --------- --------- --
> ----
>
>
>
>
>
>
> Post your message to: psychtoolbox@ yahoogroups. com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox .org
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>




Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.



Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small Business.

This is one common situation where it would be very nice for
psychtoolbox to support the OS's inbuilt notion of event queues. The
OS automatically records all keypresses and mouse movements (and the
time they occurred!) in a queue while your program is doing other
things like updating the display. You can read events out of the queue
manually, or ask the OS to invoke a callback function in your code
when a particular kind of event happens. Mac OS 9 and X do it, Windows
does it, X11 does it, and so on. Java has a platform-independent
implementation which you might be able to make work with MATLAB.

Almost every software application on your computer works by
interacting with the event queue -- looping while constantly checking
your keyboard state is something practically no one has done since the
DOS days.

Given the quite ordinary requirement to run a simulus display while
collecting input from the user, I'm sort of baffled that Psychtoolbox
does not support this mechanism.

On 8/29/06, Keith Schneider <ks@...> wrote:
>
>
>
>
>
>
> Hi Virginie,
>
> Let me reiterate that the KbCheck returns the instantaneous state of the
> keyboard, that is, which keys are being pressed at the very moment that you
> call the function. Therefore, within a trial, you should stop checking the
> keyboard after the first time at which the KbCheck function indicates that a
> key is being pressed. If you keep calling the function every few
> milliseconds, the function will report that the key that was pressed is
> still pressed. It takes some time for the key to be pressed and then
> released.
>
> I don't know how your code is structured exactly, but you can also implement
> a check to make sure all the keys are released before continuing to the next
> trial.
>
> keith
>
>
> On Aug 29, 2006, at 4:04 PM, Virginie van Wassenhove wrote:
> Hi Keith,
>
> thanks for the code snippet. I have tried to implement it (within the
> iteration loop) but it is still not stable. It seems that a WaitSecs of 1ms
> is too short -i.e. it does not seem to flush out the previous keypresses -
> and 10 to 100ms either partially reports the key presses, not at all, or too
> many....
> I'll try and work around these things some more
>
> Thanks again!
> Virginie
>
> Keith Schneider <ks@...> wrote:
>
>
> Dear Virginie,
>
> This seems like the problem then. You will need to have another loop within
> your iteration that continually calls KbCheck, with a waitsecs(0.001) also
> to ensure that the CPU isn't overloaded.
>
> I'd suggest something like this:
>
> exit_time = GetSecs + iteration_duration;
> while(GetSecs < exit_time)
> [keyisdown, secs, keycode] = KbCheck;
> if keyisdown
> break
> end
> waitsecs(0.001)
> end
>
> This will continually poll your keyboard, breaking out of the loop once a
> key is pressed, or exiting when the specified duration has elapsed. You can
> do other things if you need to within the loop as well.
>
> keith
>
>
> On Aug 29, 2006, at 1:30 PM, Virginie van Wassenhove wrote:
> Dear Keith,
>
> yes this is in fact an issue. I have tried to use the KbCheck within the
> 'if' statement (in addition to within the 'while') or create another 'while'
> statement for the KbCheck before the while pertaining to the iteration. None
> of these two worked.
>
> Each iteration is ~550ms but can vary with stimulus length, no longer than
> 1s -I don't expect to have multiple key presses during that time.
>
> Thanks,
> Virginie
> Keith Schneider <ks@...> wrote:
>
>
> Dear Vvanwass,
>
> Looking at your script briefly, it looks like you are polling the
> keyboard only once per "iteration". How long is each iteration? You
> should be polling the keyboard every few milliseconds at least.
> Remember, the KbCheck function only tells you whether a key is
> depressed at the instant that the function is called.
>
> keith
>
> On Aug 29, 2006, at 1:01 PM, vvanwass wrote:
>
> > Hello List,
> >
> > I'd like to have responses recorded continuously while various stimuli
> > are being presented (by recorded I mean (1) the key that was pressed
> > and (2) the 'reaction time' from trial onset). There is no constraint
> > as to when the participant is to respond (hence before, during or
> > after each stimulus is valid). Each trial can be as long as 5 minutes.
> >
> > I am putting an excerpt of the script below. This is not currently
> > doing the job. I have tried a couple different ways but somehow I
> > never get the full set of responses. (i.e. if I test myself and press
> > 10 times a key during the period, only 2 of them might be recorded).
> >
> > I have tried to change the position of the KbCheck in and out of the
> > loop, create a timing loop before and including the trial
> > presentation...I am sure there is a very simple way to do this, but I
> > can't seem to find it....
> >
> > Any help would be most appreciated!! Thanks in advance!
> >
> > (System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
> >
> >
> > Actual Trial loop:
> >
> > %%%%%%%%%%%
> > for i = 1:length(condOrder)
> >
> > Screen('FillRect',w, black);
> > drawFixation(FIX_COLOR);
> > Screen('Flip', w);
> >
> > if condOrder(i) == 1
> > deviant = deviantC1;
> > devname = 'deviantC1';
> > [...]
> > else
> > deviant = deviantD3;
> > devname = 'deviantD3';
> > end
> >
> > % ----- initialization variables ------
> > idx = 1;
> > j = 0;
> >
> > rtime = [];
> > keyPresses=[];
> > keyTimes =[];
> > devTimes = [];
> >
> > tic;
> > iterations = 20;
> > numdeviants = 3;
> >
> > % randomly determine timing of deviants
> > tmp = Shuffle(1:5:iterations);
> > j_rnd = sort(tmp(1:numdeviants));
> > % ----- end initialization variables ------
> >
> >
> > k = j_rnd(idx);
> >
> > TrialTime = GetSecs;
> >
> >
> > while j <= iterations
> > k = j_rnd(idx);
> >
> > [keyIsDown,secs,keyCode]= KbCheck();
> > keyNumber = getKeyNumber(keyCode); % get numerical value
> >
> > if ~ isempty(keyNumber)
> > keyPresses = [keyPresses keyNumber];
> > keyTimes= [keyTimes secs];
> > end
> >
> > if j == k
> > devTime = GetSecs;
> > devTimes = [devTimes devTime];
> >
> > sound (deviant,fs);
> > idx = idx + 1;
> >
> > if idx > length(j_rnd)
> > idx = 1;
> > end
> > else
> > sound(triplet,fs);
> > end %if
> >
> > j=j+1;
> >
> > end %while j
> > endtime = clock;
> >
> >
> > %%% sub-function, end of script
> > %----------------------------------------------------------
> > ----
> > function keyNumber = getKeyNumber( keyCode )
> > global ESC_KEY
> > keyNumber=[];
> > for i=1:length(keyCode)
> > if keyCode(i)
> > keyName=upper(KbName(i)); %get the key name from the
> > keyboard key index
> > if strcmp(keyName, ESC_KEY)
> > error('ESCAPE key detected');
> > end
> > keyNumber=str2num(keyName); %turn the key name into a
> > number
> > return; %return once the first key pressed is found
> > end
> > end
> > %----------------------------------------------------------
> > ----
> >
> >
> >
> >
> >
> >
> > Post your message to: psychtoolbox@yahoogroups.com
> > Please indicate OS9, OSX, or WIN version, and include your full name.
> > Denis Pelli, David Brainard, and Allen Ingling.
> > http://psychtoolbox.org
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
> ________________________________
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail.
>
>
> ________________________________
> Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small
> Business.
>
>
>
Hi

this is to give an update on this issue...  CharAvail and GetChar in v1.0.6 beta works very well for the purpose of recording key presses at anytime/continuously during the script.

Thanks all for your help/comments on this and double-thanks to Chris for the very fast updates!

-Virginie

Christopher Broussard <chrg@...> wrote:
Hi Virginie
    I'm currently reworking the implementation of GetChar and CharAvail, which may be what you want to use.  It essentially buffers all keypresses in the background and let's you pull them out at your leisure.  KbCheck is quite fast, but unfortunately, as you have had happen, can miss keypresses if you don't time it right.  GetChar  also records when the key was pressed so you can keep track of that information.  I'm finishing up the final touches on it right now and hopefully I can get it into the beta today or tomorrow.

    -Christopher Broussard-

Virginie van Wassenhove wrote:
Hi Keith,

thanks for the code snippet. I have tried to implement it (within the iteration loop) but it is still not stable. It seems that a WaitSecs of 1ms is too short -i.e. it does not seem to flush out the previous keypresses - and 10 to 100ms either partially reports the key presses, not at all, or too many....
I'll try and work around these things some more

Thanks again!
Virginie

Keith Schneider <ks@.... edu> wrote:
Dear Virginie,

This seems like the problem then.  You will need to have another loop within your iteration that continually calls KbCheck, with a waitsecs(0.001) also to ensure that the CPU isn't overloaded.

I'd suggest something like this:

exit_time = GetSecs + iteration_duration;
while(GetSecs < exit_time)
   [keyisdown, secs, keycode] = KbCheck;
   if keyisdown
    break
  end
  waitsecs(0.001)
end

This will continually poll your keyboard, breaking out of the loop once a key is pressed, or exiting when the specified duration has elapsed.  You can do other things if you need to within the loop as well.

keith

On Aug 29, 2006, at 1:30 PM, Virginie van Wassenhove wrote:

Dear Keith,

yes this is in fact an issue. I have tried to use the KbCheck within the 'if' statement (in addition to within the 'while') or create ano! ther 'wh ile' statement for the KbCheck before the while pertaining to the iteration. None of these two worked.

Each iteration is ~550ms but can vary with stimulus length, no longer than 1s -I don't expect to have multiple key presses during that time.

Thanks,
Virginie
Keith Schneider <ks@.... edu> wrote:
Dear Vvanwass,

Looking at your script briefly, it looks like you are polling the
keyboard only once per "iteration". How long is each iteration? You
should be polling the keyboard every few milliseconds at least.
Remember, the KbCheck function only tells you whether a key is
depressed at the instant that the function is called.

keith

On Aug 29, 2006, at 1:01 PM, vvanwass wrote:

> Hello List,
>
> I'd like to have responses recorded continuously while various stimuli
> are being presented (by recorded I mean (1) the key that was pressed
> and (2) the 'reaction time' from trial onset). There is no constraint
> as to when the participant is to respond (hence before, during or
> after each stimulus is valid). Each trial can be as long as 5 minutes.
>
> I am putting an excerpt of the script below. This is not currently
> doing the job. I have tried a couple different ways but somehow I
> never get the full set of responses. (i.e. if I test myself and press
> 10 times a key during the period, only 2 of them might be recorded).
>
> I have tried to change the position of the KbCheck in and out of the
> loop, create a timing loop before and including the trial
> presentation. ..I am sure there is a very simple way to do this, but I
> can't seem to find it....
>
> Any help would be most appreciated! ! Thanks in advance!
>
> (System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
>
>
> Actual Trial loop:
>
> %%%%%%%%%%%
> for i = 1:length(condOrder)
>
> Screen('FillRect' ,w, black);
> drawFixation( FIX_COLOR) ;
> Screen('Flip' , w);
>
> if condOrder(i) == 1
> deviant = deviantC1;
> devname = 'deviantC1';
> [...]
> else
> deviant = deviantD3;
> devname = 'deviantD3';
> end
>
> % ----- initialization variables ------
> idx = 1;
> j = 0;
>
> rtime = [];
> keyPresses=[ ];
> keyTimes =[];
> devTimes = [];
>
> tic;
> iterations = 20;
> numdeviants = 3;
>
> % randomly determine timing of deviants
> tmp = Shuffle(1:5: iterations) ;
> j_rnd = sort(tmp(1:numdevia nts));
> % ----- end initialization variables ------
>
>
> k = j_rnd(idx);
>
> TrialTime = GetSecs;
>
>
> while j <= iterations
> k = j_rnd(idx);
>
> [keyIsDown,secs, keyCode]= KbCheck();
> keyNumber = getKeyNumber( keyCode); % get numerical value
>
> if ~ isempty(keyNumber)
> keyPresses = [keyPresses keyNumber];
> keyTimes= [keyTimes secs];
> end
>
> if j == k
> devTime = GetSecs;
> devTimes = [devTimes devTime];
>
> sound (deviant,fs) ;
> idx = idx + 1;
>
> if idx > length(j_rnd)
> idx = 1;
> end
> else
> sound(triplet, fs);
> end %if
>
> j=j+1;
>
> end %while j
> endtime = clock;
>
>
> %%% sub-function, end of script
> %----------- --------- --------- --------- --------- --------- --
> ----
> function keyNumber = getKeyNumber( keyCode )
> global ESC_KEY
> keyNumber=[] ;
> for i=1:length(keyCode)
> if keyCode(i)
> keyName=upper( KbName(i) ); %get the key name from the
> keyboard key index
> if strcmp(keyName, ESC_KEY)
> error('ESCAPE key detected');
> end
> keyNumber=str2num( keyName); %turn the key name into a
> number
> return; %return once the first key pressed is found
> end
> end
> %----------- --------- --------- --------- --------- --------- --
> ----
>
>
>
>
>
>
> Post your message to: psychtoolbox@ yahoogroups. com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox .org
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>




Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.



Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small Business.


Stay in the know. Pulse on the new Yahoo.com. Check it out.