Skip to content

Commit

Permalink
NF: Finalised JS keyboard code compile based on PsychoPy PTB KB port
Browse files Browse the repository at this point in the history
  • Loading branch information
dvbridges committed Jul 16, 2019
1 parent 7f38203 commit e328378
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions psychopy/experiment/components/keyboard/__init__.py
Expand Up @@ -141,7 +141,7 @@ def writeRoutineStartCode(self, buff):
return

def writeRoutineStartCodeJS(self, buff):
code = "%(name)s = new core.Keyboard({psychoJS, waitForStart: true});\n\n"
code = "%(name)s = new core.Keyboard({psychoJS, clock: new util.Clock(), waitForStart: true});\n\n"
buff.writeIndentedLines(code % self.params)

if (self.params['store'].val == 'nothing' and
Expand Down Expand Up @@ -334,15 +334,22 @@ def writeFrameCodeJS(self, buff):

if store != 'nothing':
if self.params['syncScreenRefresh'].val:
code = ("psychoJS.window.callOnFlip(function() { %(name)s.start(); }); "
code = ("psychoJS.window.callOnFlip(function() { %(name)s.clock.reset(); }); "
"// t=0 on next screen flip\n"
"psychoJS.window.callOnFlip(function() { %(name)s.start(); }); "
"// start on screen flip\n") % self.params
else:
code = "%(name)s.start();\n" % self.params
code = ("%(name)s.clock.reset();\n"
"%(name)s.start();\n") % self.params

buff.writeIndented(code)
buff.writeIndentedLines(code)

if self.params['discard previous'].val:
buff.writeIndented("%(name)s.clearEvents();\n" % self.params)
if self.params['syncScreenRefresh'].val:
buff.writeIndented("psychoJS.window.callOnFlip(function() { %(name)s.clearEvents(); });\n"
% self.params)
else:
buff.writeIndented("%(name)s.clearEvents();\n" % self.params)

# to get out of the if statement
buff.setIndentLevel(-1, relative=True)
Expand Down

0 comments on commit e328378

Please sign in to comment.