Online: "keyboard is not defined" when running JS generated from Python

I have the following line in Begin Routine for a code component:

mykb = keyboard.Keyboard()

This gets transpiled to the following JS:

  mykb = new keyboard.Keyboard();

which gives the following error:

On the other hand, when I create a Keyboard component, the following JS is generated:

  key_resp = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});

which seems to work OK.

I have tried to change the JS file so that the first line uses core.Keyboard rather than keyboard.Keyboard. This makes the error go away, but causes a new error:

which appears to come from keyboard.js:

How should I go about debugging this? Is there a different way to write the Python code so that it gets transpiled correctly?

I realised thanks to this thread:

that one should initialise the keyboard object like this:

  mykb = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});

This does remove the error. However nothing happens when I press a key (the Python version, running locally, decreases grating contrast).

Even if this did work, it seems that I would have to edit the JS file manually every time it was generated - is there a different approach?

I attach the experiment and generated JS:

Archive.zip (6.0 KB)

I’ve also tried

  mykb = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: false});

with the same effect: the keypress is not registered.

Could it be because this is what is generated from Python:

keys = key_resp.getKeys(['left','right', 'up', 'down'], {"waitRelease": false, "clear": true});

but this is what is generated from the Builder component:

   let theseKeys = key_resp.getKeys({keyList: ['y', 'n', 'left', 'right', 'space'], waitRelease: false});