function out=getResp
%for symbolic identification experiment (SID)
%waits for mouse click on any response circle
%returns location of circle and response time

global respX respY respSize

beginTime = GetSecs;

for i=1:256 %flush mouse buffer
    GetMouse;
end

[x,y,buttons] = GetMouse;
choice = 0;
while choice==0
    while any(buttons) % if already down, wait for release
        [x,y,buttons] = GetMouse;
    end
    while ~any(buttons) % wait for press
        [x,y,buttons] = GetMouse;
        [keyIsDown,secs,lastKey] = KbCheck;
        key = KbName(lastKey);
        if escapeSequence(key)
            disp 'Escape sequence activated'
            out = [-1 GetSecs-beginTime];
            return;
        end
    end
    respOn = 0;
    for i=1:9 %check mouse location against response circles
        if (x-respX(i))^2 + (y-respY(i))^2 < respSize^2
            respOn = i;
        end
    end
    if respOn==0
        continue
    end
    while any(buttons) % wait for release
        [x,y,buttons] = GetMouse;
    end
    if (x-respX(respOn))^2 + (y-respY(respOn))^2 < respSize^2
        choice = respOn;
    end
end
out = [choice, GetSecs-beginTime];
