mousetracker.callback

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.

Example:

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

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