% GetTheResponsePD
%
% Subscript that holds the very messy code for getting the
% response in the PhaseDistortDemo program.
%
% Since this is a script, it uses the same workspace as the
% main program.
%
% 3/5/97  dhb  Pulled out of main script.
% 3/24/98  dgp  Changed obsolete GetKey to new GetChar.
% 4/08/02  awi  Check for any mouse button. 

ShowCursor(5);
SetMouse(homeX,homeY);
while 1
	theKey = -1;
	correct = -1;
	while 1
		if CharAvail
			theKey = GetChar;
			if (theKey == 'q')
				break;
			end
		end
		[mouseX,mouseY,mouseButton] = GetMouse;
		if any(mouseButton)
			break;
		end
	end
	if (theKey == 'q')
		break;
	end
	if (theSide == 0)
		if (IsInRect(mouseX,mouseY,theRect1))
			correct = 1;
			break;
		elseif (IsInRect(mouseX,mouseY,theRect2))
			correct = 0;
			break;
		end
	else
		if (IsInRect(mouseX,mouseY,theRect1))
			correct = 0;
			break;
		elseif (IsInRect(mouseX,mouseY,theRect2))
			correct = 1;
			break;
		end
	end
	if (correct > 0)
		break;
	end
end
if (theKey == 'q')
	break;
end
respString = sprintf('Trial %3d at %4.2f is %s\n',k,pTest,wrongRight(correct+1,:));
Screen(window,'DrawText',respString,50,150,255);
GiveFeedback(correct);
	
