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:
opened 06:22AM - 23 May 20 UTC
closed 06:24AM - 04 Jul 20 UTC
Hi,
Sorry if this is not a place where I should be posting this...
I've … currently converted the python code into javascript. However, it seems that I require Psychojs to my project. Do you have anything inside your `README.md` file which beginner could use as a starting point?
Thanks a lot!
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});