getMouseTracker(id).callback( command )

or getMouseTracker(id).callback( function )

Will run the PennController command(s) or javascript function passed as arguments whenever the mouse moves after start and before stop have been called.

If you pass a function, it will be receive two arguments when executed, corresponding to the current X and Y coordinates.


[js highlight=”9-15″ try=”true”]newButton(“Click then move your mouse when seeing a box”)
.print(“center at 50vw”, “center at 50vh”)
newCanvas(“box”, 100, 100).css(“background”, “black”)
.success( newText(“Good job!”).print() )
.failure( newText(“Missed it!”).print() )
newTimer( 200+800*Math.random() ).start().wait()
newTimer( 200+300*Math.random() ).start().wait()

Starts a MouseTracker element once the button is clicked, waits between 200ms and 1s before printing a black square on the page and removes it after a time period between 200ms and 500ms. The callback command will run whenever the mouse starts moving after a click on the button, and will print a different message depending on whether the Canvas element is on the page, and will immediately stop the MouseTracker element, making sure the callback is called only once.

Published by Jeremy

Researcher in semantics and pragmatics; Programmer of PennController for IBEX