getEyeTracker(id).callback( function ) (since PennController 1.8)

Tell the script to continuously execute the specified javascript function as long as an element is being looked at.

The function takes is passed two arguments, the estimated X and Y coordinates. The keyword this in the callback function points to the PennElement instance corresponding to the looked-at element.


[js highlight=”13″ try=”data”]newTrial( newButton(“Start”).print().wait(newEyeTracker().test.ready()) )

newText(“lookedAt”, “”).print()
newText(“Left”).css(“padding”,”20vw”).print(“20vw”, “40vh”),
newText(“Right”).css(“padding”,”20vw”).print(“60vw”, “40vh”)
.add( getText(“Left”) , getText(“Right”) )
.callback(function(x,y){ getText(“lookedAt”).text(`Looking at ${this.id} (${x},${y})`)._runPromises(); })
newSelector().add( getText(“Left”) , getText(“Right”) ).wait()

Will display the name of the element being looked-at, along with the X and Y coordinates.

Published by Jeremy

Researcher in semantics and pragmatics; Programmer of PennController for IBEX