Hello,
I am trying to collect typed responses in an online experiment, through Pavlovia. I managed to make my textbook work with the following code in a code component:
In Begin experiment:
allLetters = [“q”, “w”, “e”, “r”, “t”, “y”, “u”, “i”, “o”, “p”, “a”, “s”, “d”, “f”, “g”, “h”, “j”, “k”, “l”, “z”, “x”, “c”, “v”, “b”, “n”, “m”];
In BeginRoutine:
textFill = "the ";
In EachFrame:
var _pj;
function _pj_snippets(container) {
function in_es6(left, right) {
if (((right instanceof Array) || ((typeof right) === “string”))) {
return (right.indexOf(left) > (- 1));
} else {
if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
return right.has(left);
} else {
return (left in right);
}
}
}
container[“in_es6”] = in_es6;
return container;
}
_pj = {};
_pj_snippets(_pj);
keys = psychoJS.eventManager.getKeys();
if (_pj.in_es6(“escape”, keys)) {
core.quit();
} else {
if (keys) {
if ((keys[0] === “space”)) {
textFill += " ";
} else {
if ((keys[0] === “backspace”)) {
textFill = textFill.slice(0, (- 1));
} else {
if (_pj.in_es6(keys[0], allLetters)) {
textFill += keys[0];
}
}
}
textbox_production.setText(textFill);
}
}
Then, I refer to the variable “textFill” in a textbook component, with “text”: $textFill
My textbook works well: I manage to collect typed words. However, I don’t know how to collect typed numbers and symbols, such as the dash in the word “t-shirt”. I would need these symbols for my experiment.
I tried to list them in the variable allLetters, but this doesn’t work. What else can I do?
Thanks a lot!