Я добавил следующий код для перемещения стимула на экране, и я только что заметил, что это, похоже, отключает возможность выхода из кода с помощью клавиши «escape» в любом месте скрипта. Я все еще новичок в Javascript, любые указатели будут оценены.
//the following appears a few time throughout the script
// check for quit (typically the Esc key)
if (psychoJS.experiment.experimentEnded ||
psychoJS.eventManager.getKeys({ keyList: ['escape'] }).length > 0) {
return quitPsychoJS('The [Escape] key was pressed. Goodbye!', false);
}
// and then later in the script
// FRR ----- manual entry BEGIN; copy this before "function TestRoutineBegin(trials) {"
// code to move stimulus
var xforce;
spacepressed = 0; // reset each trial
xforce = 0; // initially set speed ('force') to 0. It increases in steps of 1 as long as key is down
function resetXforce (event) {
xforce = 0; // if finger has been lifted, go back to speed 0
}
function getKeyResponse (event) { // check for responses
//psychoJS.eventManager.clearEvents({eventType:'keyboard'});
var thisResp = psychoJS.eventManager.getKeys();
console.log(thisResp);
if (spacepressed == 0) {
if ('left' == thisResp[0]) {
xforce--; // decrease angle with increasing acceleration the longer key pressed
angle = (angle + xforce); //plus not minus here since xforce may become negative
myx = (0.25 * Math.sin((((Math.PI * 2) * angle) / 360)));
myy = (0.25 * Math.cos((((Math.PI * 2) * angle) / 360)));
//smallcircle2.setPos([myx, myy]);
image_on_circ_test.setPos([myx, myy]);
}
if ('right' == thisResp[0]) {
xforce++; //increase angle with increasing acceleration the longer key pressed
angle = (angle + xforce);
myx = (0.25 * Math.sin((((Math.PI * 2) * angle) / 360)));
myy = (0.25 * Math.cos((((Math.PI * 2) * angle) / 360)));
//smallcircle2.setPos([myx, myy]);
image_on_circ_test.setPos([myx, myy]);
}
if ('space' == thisResp[0]) {
LocCol2 = 'white'; // if response locked with spacebar
//document.removeEventListener("keydown", getKeyResponse); //once spacebar is pressed, dont except any more input
spacepressed = 1;//new 28.05 15:55
}
/* if (psychoJS.eventManager.getKeys({keyList:['space']}).length > 0) {
LocCol2 = 'white' // if response locked with spacebar
spacepressed = 1;
}*/
psychoJS.eventManager.clearEvents({ eventType: 'keyboard' });
}
}
window.addEventListener('keydown', getKeyResponse); //tried keydown as well, with the same problem
window.addEventListener('keyup', resetXforce);
// FRR------------------------------------------------------------------------------