• TypeError: Cannot use 'in' operator to search for 'backspace' in undefined

I’m trying to get participants to type answers to multiplication problems. The study runs well offline, but when I run it in Pavlovia I get this message:
• TypeError: Cannot use ‘in’ operator to search for ‘backspace’ in undefined
Could you help me find what’s wrong?
Thanks, Smadar

This is what’s written in my code:
Begin routine:
screen_text = ‘’

each frame:
if(“backspace” in key_Resp.keys):

if(len(key_Resp.keys) > o):

elif(“return” in key_Resp.keys):
screen_text = ‘’.join(key_Resp.keys)
thisExp.addData(“recall_resp”, screen_text)

continueRoutine = False  

screen_text = ‘’.join(key_Resp.keys)

You’re showing us the Python code, but in running online, the JavaScript equivalent will be used, so that should be shown instead.

I’m not that familiar with JavaScript, but I guess it is telling you that the list of keys has not been created yet and so can’t be tested to see if it contains an entry. Try shifting your code component below the keyboard component so the code runs after it. If that doesn’t work, try coding defensively, so that the test is only conducted if the list of keys exists.


I moved the code to be under the keyboard but that did not solve the problem. Your other advise I did not quite understand. Could you elaborate?

Here is the JS:

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 = {};


if (_pj.in_es6(“backspace”, key_Resp.keys)) {


if ((key_Resp.keys.length > 0)) {



} else {

if (_pj.in_es6(“return”, key_Resp.keys)) {


screen_text = “”.join(key_Resp.keys);

thisExp.addData(“recall_resp”, screen_text);

continueRoutine = false;



screen_text = “”.join(key_Resp.keys);

Is there a video guide (beside the one by Jason Ozubko) or simple written guidelines for getting typed responses in psychopy? - Not via textbox?

Alternatively, is it possible for one of you to remotely take control of my computer (if that’s the right phrase in English) and help me solve this? Do you have this kind of support team? .

Thanks a lot for your help so far.




Try putting

if key_Resp.keys: if “backspace” in key_Resp.keys and len(key_Resp.keys)>1: key_Resp.keys.pop() key_Resp.keys.pop()

If never tried this method myself but in principle it should remove the final two keys if the final key is backspace.