Can't collect typed numbers and symbols in textbook responses on Pavlovia

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!

Have a look at my key check online demo

Thanks! I managed to include the desired symbols.

I tried to allow also upper case letters, by including your snipped of code:

else {
if ((_pj.in_es6(“lshift”, keys) || _pj.in_es6(“rshift”, keys))) {
modify = true;
} else {
if ((modify === false)) {
textFill += keys[0];
}
}

However, now I get that in my textbox, as soon as I open it, “undefined” is printed multiple times. Do you have an intuition of why?

You need to ensure that this code is only run when there is a valid value for keys[0]

e.g.

keys = event.getKeys()
if len(keys):
   ...