Failing to use Keyboard in Pavlovia

Just developed an experiment in Pilot mode. It uses a Code component that includes

my_keyboard = keyboard.Keyboard()

The experiment runs nicely in Builder, but when uploaded to Pavlovia, it throws the following error:

ReferenceError: keyboard is not defined

I assume there is something wrong in the automatic translation from Python to JS that prevents me from using keyboard function, but cannot figure it out…

Any help will be much appreciated.

@eduardugr, the JS keyboard is created differently, try the following

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

If you generate some JS code using Builder, with a keyboard component, you can see how a keyboard is set up using JS code.

2 Likes

Have you tried this? I just tested it in my template file and the following code didn’t work.

Begin Experiment (JS side of a code both)

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

Each Frame (Python auto translated to JS)

keys = event.getKeys(['y','quit'], waitRelease=True)
if 'quit' in keys:
    core.quit()
elif 'y' in keys:
    continueRoutine=False
    

There was no error but the y key did not end the routine.

Thank you this fixed my issue with the undefined keyboard error on pavlovia