Closed Remi-Gau closed 3 years ago
Added a checkAbort function that checks that the the cfg.escapeKey has been pressed and throws an error to stop everything if that's the case.
This function is also called every time getResponse('check') is triggered.
@CerenB this should fix #22
TO DO
@marcobarilari once we have merged this one https://github.com/marcobarilari/CPP_PTB/pull/2 and #26
I will rebase and add cfg.escapeKey
as one of the default value for initPTB.
function
checkAbort
only would work if in the main script I'm usingfor
loop, right? It'd break the for loop withstopEverything
. What if a user is not using any for loop in their experiment?
Actually checkAbort
is pretty "aggressive" at the moment and will just throw an error so it will stop everything no matter what (even with no loop).
I trying to think of a way to make it abort more "gracefully" (like give a chance to save stuff) and that's why I wanted to create a global variable.
Or do you think this is OK?
well I was thinking that warning
instead of error would be nicer. Unfortunately I could not make this abort work even with the error
, even with a long press.
stopEverything
? could it be related to touch screen macbook esc button? Though, same touch button works with below snippet:
% stay in the loop until the sequence ends
while GetSecs < (expParam.experimentStart + audioDuration + ...
expParam.timing.onsetDelay + expParam.timing.endDelay)
% check if key is pressed
[keyIsDown, ~, keyCode] = KbCheck(cfg.keyboard);
% terminate if quit-button pressed
if find(keyCode)==cfg.escapeKey
error('Experiment terminated by user...');
end
end
I don't think this should be related to stopEverything
.
I have added a demo that should work and is very similar to what you sent.
If this does not work try setting the cfg.escapeKey to space
and check if this works when you press the space bar.
At least we will know this is likely not "key" related.
Been thinking of how to implement this "abort" as part of getResponse.
At the moment getResponse only checks the response box, not the keyboard of the experimenter. So the only way to make this "abort" thing work woud be to ask getResponse to check for keypresses on all devices.
I could make this the default and listening to the responseBox would have to be asked for.
that's one of points I got stuck with in getResponse function. I thought now it's listening to all key presses. OR is it? It's listening to responseBox specific button presses, but in keyboard all presses? Maybe when I was checking on Friday, I got stuck at this point because I specified the keys to check but it was checking all the key presses (no additional keyboards were connected than built in mac keyboard)
to respond to your question, how about separate these two functions completely? Both uses KbQueue checks/buffering. Aborting function checks keyboard and aborts things - maybe there's a way to do it smoothly when things are independent two functions?
function
checkAbort
only would work if in the main script I'm usingfor
loop, right? It'd break the for loop withstopEverything
. What if a user is not using any for loop in their experiment?Actually
checkAbort
is pretty "aggressive" at the moment and will just throw an error so it will stop everything no matter what (even with no loop).I trying to think of a way to make it abort more "gracefully" (like give a chance to save stuff) and that's why I wanted to create a global variable.
Or do you think this is OK?
Maybe, since it prompts an error, we can have something in the catch
part that will save everything (workspace, button presses in the buffer and close the file, eye tracker data, etc).
Does it make sense?
to respond to your question, how about separate these two functions completely? Both uses KbQueue checks/buffering. Aborting function checks keyboard and aborts things - maybe there's a way to do it smoothly when things are independent two functions?
Need to check if we can have to KbQueues going in parallel.
that's one of points I got stuck with in getResponse function. I thought now it's listening to all key presses. OR is it? It's listening to responseBox specific button presses, but in keyboard all presses? Maybe when I was checking on Friday, I got stuck at this point because I specified the keys to check but it was checking all the key presses (no additional keyboards were connected than built in mac keyboard)
So by default getResponse listens to the responseBox but if you have only one device then the keyboard and the responseBox should be the same.
Did you specify the keys to check like this?
expParameters.responseKey = {'a', 'b', 'c'};
OK what I am thinking of starting to do is to have getResponse and the abort function to check for all devices by default (to make it most general) and then implement a way to let the user decide which device (keyboard or response box), each function should listen to.
This will require some changes to the default and the initPTB I think but nothing crazy.
This might make things less confusing for most new PTB users so that's not bad.
OK so a series of changes on all the keyboard functions:
cfg.keyboard
catch
to get them and allows us to "close" nicely (not sure how to keep yet unsaved responses though)Similarly will merge in 24 hours unless I get a veto. :smile:
A lot of refactoring and @CerenB this should also fix #19 and problem of extra responses you were getting from getResponses.