unusual code error

Hi group,

i seem to be having a strange problem, i've had to place some of my
code inside a wrapper class, for timing reasons but for some reason
when i do this, the start of code that requires a user keypress to
initiate the program does not work. Also if i try to use GetChar or
GetClicks to start the program, then the mouse does not work and no
reaction times are taken

any one got any ideas??????

Thanks,

Niall.


code
***************************
clear all;
HideCursor;
[w,windowRect]=Screen(0,'OpenWindow',[0 0 0],[]);% ?
white=WhiteIndex(w);
black=BlackIndex(w);
gray=(white+black)/2;

ante=Screen(w,'OpenOffscreenWindow',black);
Screen(w,'WaitBlanking');
Screen(ante,'DrawText','Please hit a key to start', 300,300,white);

Screen('CopyWindow',ante,w);%
KbWait;

%GetChar;

[keyIsDown,secs,keyCode] = KbCheck;
FlushEvents('keyDown');
Screen(ante,'Close');
Screen(w,'FillRect',black);

%GetClicks;

Screen (w,'DrawLine',gray+20,482, 384, 542, 384,[3],[]);
Screen (w,'DrawLine',gray+20,512, 414, 512, 354,[3],[]);

xa=[880 ,879 ,875 ,868 ];
ya=[384 ,415 ,445 ,476 ];

WaitSecs (1.0);
reactime=0;
for c=1:3%change to 160
reactime=0;
pw(1)=Screen(w,'OpenOffscreenWindow',black);
h=floor(30*rand)+1;
Screen(pw(1),'FillOval',gray,[xa(h)-15,ya(h)-15,xa(h)+15,ya(h)+15]);
Screen (pw(1),'DrawLine',gray+20,482, 384, 542, 384,[3],[]);
Screen (pw(1),'DrawLine',gray+20,512, 414, 512, 354,[3],[]);
tmr=5;
val=0;

loop={
'Screen(w,''WaitBlanking'');'
'Screen(''CopyWindow'',pw(1),w);'
'startTime = GetSecs;'
'while val< tmr;'
'[x,y,buttons] = GetMouse;'
'if buttons(1);'

'clicktime=GetSecs;'
'reactime=clicktime-startTime;'
'Screen(w,''FillOval'',black,[xa(h)-15,ya(h)-15,xa(h)+15,ya(h)+15]);'

'break;'
'else;'
'val=(val+.001);'
'WaitSecs(.001);'
'end;'
'end;'
'Screen(pw(1),''Close'');'
'Screen(w,''FillOval'',black,[xa(h)-15,ya(h)-15,xa(h)+15,ya(h)+15]);'
};
priorityLevel=MaxPriority(w,'WaitBlanking');
Rush(loop,priorityLevel);
Screen(w,'FillOval',black,[xa(h)-15,ya(h)-15,xa(h)+15,ya(h)+15]);
reactime
WaitSecs(5.0);
end

************************