Code: Rebecca Lysaght / serial dependence · GitLab
Description of the problem:
Hi, I have an experiment that works locally but doesn’t run in Pavlovia. There are a couple of issues based on what I’ve read about what Pavlovia doesn’t support (I need to change some of the color values to [1,255] and some of the deg layouts to height) but the main issue I don’t know how to solve is how to replace one of my code components. It looks like this:
import {key} from ‘pyglet/window’;
var keyState;
keyState = new key.KeyStateHandler();
…
keyState = new key.KeyStateHandler();
notFinished = true;
…
imgNum = util.randint(1, 147);
imageFile = ((“female/” + imgNum.toString()) + “.bmp”);
MatchFace.setImage(imageFile, {“log”: false});
while ((notFinished === true)) {
wobmp = imageFile.slice(0, (- 4));
img = Number.parseInt(wobmp.slice(7));
psychoJS.window.winHandle.push_handlers(keyState);
if (keyState[key.LEFT]) {
if ((img === 1)) {
imageFile = “female/147.bmp”;
} else {
imageFile = ((“female/” + (img - 1).toString()) + “.bmp”);
}
MatchFace.setImage(imageFile, {“log”: false});
}
if (keyState[key.RIGHT]) {
if ((img === 147)) {
imageFile = “female/1.bmp”;
} else {
imageFile = ((“female/” + (img + 1).toString()) + “.bmp”);
}
MatchFace.setImage(imageFile, {“log”: false});
}
if (keyState[key.SPACE]) {
AdjTime = clock.getTime();
notFinished = false;
continueRoutine = false;
}
if (keyState[key.ESCAPE]) {
core.quit();
}
psychoJS.window.flip();
}
Basically on every right or left click I want to update my image component and on space I want to stop taking keyboard input and move on to the next loop. I read that Pavlovia doesn’t support KeyStateHandler but what can I replace it with? My understanding of the Keyboard component in the Builder is that it stores/returns all keys pressed - I need a way to pause after every key press (could be anywhere from 1 to over a hundred) to update the image component.
Any help would be greatly appreciated, thank you.