Use of Kb commands

Dear all,
I've created a program that shows alternatively at a fixed frequency
(15 Hz) sinusoidal red-green or yellow-blue gratings; the max and
min luminance (v coordinate of hsv color space) of the grating can
be vary by pressing the 'UpArrow' and 'DownArrow' on the keyboard.
The problem is that everytime I'd like to change the relative
luminance, the gratings stop alternating and Matlab takes some
seconds to restart showing the gratings with the new mean luminance
(and so with the new min and max luminance of the grating).
Is there a way to get a continuos change ?

I attached the main part of the program (KbDemo has been very useful
for me!).
creasinusoideG is the function that creates the two alternating
images whose luminance vary from a minimum to a max value. The two
images (img1 and img2) are created in this way:
img1= red-black sinusoidal grating + green-black sinusoidal grating
(added 180 ° out of phase)=red-green sinusoidal grating
img2= green-black sinusoidal grating + red-black sinusoidal grating
(added 180 ° out of phase)=green-red sinusoidal grating
Red and Green vary sinusoidally fom a minimum to a maximum value of
luminance that depends on the mean luminance of the color and on the
contrast. The color HSV coordinates are then transformed in RGB
coordinates.


Lr=0.4; % Initial mean brightess of red grating Lg=1-Lr green mean
brightness
KbName('UnifyKeyNames');
escapeKey = KbName('ESCAPE');
UpKey=KbName('UpArrow');
DownKey=KbName('DownArrow');


[img1 img2]=creasinusoideG(Lr,frspaz,heightnew,s,contrast); %It
creates the first two images (img1 and img2) that alternate
sinusoidally at a fixed frequency
uno=Screen(window,'MakeTexture',img1);
due=Screen(window,'MakeTexture',img2);

while 1
Screen(window,'DrawTexture',uno,[0 0 width newdim],[0 0 width
newdim]);
t=Screen(window,'Flip',t+WaitTemp-slack);

Screen(window,'DrawTexture',due,[0 0 width newdim],[0 0 width
newdim]);
t=Screen(window,'Flip',t+WaitTemp-slack);

[ keyIsDown, seconds, keyCode ] = KbCheck;

if keyIsDown
if keyCode(UpKey)
if Lr==1
Lr=Lr;
else
Lr=Lr+0.025;
[img1 img2]=creasinusoideG(Lr,frspaz,heightnew,s,contrast);
uno=Screen(window,'MakeTexture',img1);
due=Screen(window,'MakeTexture',img2);
end
lumRosso=[lumRosso Lr];
end

if keyCode(DownKey)
if Lr==0
Lr=Lr;
else
Lr=Lr-0.025;
[img1 img2]=creasinusoideG(Lr,frspaz,heightnew,s,contrast);
uno=Screen(window,'MakeTexture',img1);
due=Screen(window,'MakeTexture',img2);
end
lumRosso=[lumRosso Lr];
end

if keyCode(escapeKey)
break;
end
while KbCheck;
end
end
end

Any help will be appreciated!
Many thanks in advance!!!

Roberta