-
Notifications
You must be signed in to change notification settings - Fork 0
/
getResp.m
executable file
·36 lines (34 loc) · 1.12 KB
/
getResp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function varargout = getResp(varargin)
%function varargout = GetResp(varargin)
% If no variables are supplied as input, then no variables are supplied as output.
% The function simply returns [RT].
% If characters are supplied as input then the output is [Response, RT]
% E.g. For GetResp('z', 'x', 'n'), Response is
% 1 if 'z' was pressed,
% 2 if 'x' is pressed, or
% 3 if 'n' is pressed.
beginTime = GetSecs;
responded = 0;
while ~responded
[keyIsDown,secs,keyCode] = KbCheck;
lastKey = keyCode;
while keyIsDown, [keyIsDown,secs,keyCode] = KbCheck; end;
while ~keyIsDown
[keyIsDown,secs,keyCode] = KbCheck;
lastKey = keyCode;
end
key = KbName(lastKey);
if isempty(varargin)
responded = 1;
varargout = {GetSecs-beginTime};
else
for i = 1:length(varargin)
if isequal(upper(key), upper(varargin{i}))
responded = 1;
varargout = {i, GetSecs-beginTime};
end
end
end
end
[keyIsDown,secs,keyCode] = KbCheck;
while keyIsDown, [keyIsDown,secs,keyCode] = KbCheck; end;