Skip to content

Commit 252f20e

Browse files
committed
refactor get all key events
1 parent 3ba28cb commit 252f20e

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

getResponse.m

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,7 @@
8080

8181
case 'check'
8282

83-
iEvent = 1;
84-
85-
while KbEventAvail(responseBox)
86-
87-
event = KbEventGet(responseBox);
88-
89-
% we only return the pressed keys by default
90-
if getOnlyPress && event.Pressed==0
91-
else
92-
93-
responseEvents(iEvent,1).onset = event.Time;
94-
responseEvents(iEvent,1).trial_type = 'response';
95-
responseEvents(iEvent,1).duration = 0;
96-
responseEvents(iEvent,1).key_name = KbName(event.Keycode);
97-
responseEvents(iEvent,1).pressed = event.Pressed;
98-
99-
end
100-
101-
iEvent = iEvent + 1;
102-
103-
end
83+
responseEvents = getAllKeyEvents(responseEvents, responseBox, getOnlyPress);
10484

10585

10686
case 'flush'
@@ -185,4 +165,32 @@ function talkToMe(action, expParameters)
185165
end
186166

187167
fprintf('\n\n')
168+
end
169+
170+
171+
172+
function responseEvents = getAllKeyEvents(responseEvents, responseBox, getOnlyPress)
173+
174+
iEvent = 1;
175+
176+
while KbEventAvail(responseBox)
177+
178+
event = KbEventGet(responseBox);
179+
180+
% we only return the pressed keys by default
181+
if getOnlyPress==true && event.Pressed==0
182+
else
183+
184+
responseEvents(iEvent,1).onset = event.Time;
185+
responseEvents(iEvent,1).trial_type = 'response';
186+
responseEvents(iEvent,1).duration = 0;
187+
responseEvents(iEvent,1).key_name = KbName(event.Keycode);
188+
responseEvents(iEvent,1).pressed = event.Pressed;
189+
190+
iEvent = iEvent + 1;
191+
192+
end
193+
194+
end
195+
188196
end

0 commit comments

Comments
 (0)