I added the following cope to move a stimulus on the screen, and just noticed that this seems to disable the ability to escape the code with the ‘escape’ key anywhere in the script. I am still very new to Javascript, any pointers would be appreciated.
// 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------------------------------------------------------------------------------