PennController for IBEX › Forums › Support › MouseTracker element: Dynamic starting procedure › Reply To: MouseTracker element: Dynamic starting procedure
July 7, 2022 at 1:25 pm
#8261
Keymaster
Hi Judith,
Apologies for the late reply. You can pass a function to the callback command of the MouseTracker element that takes the x,y coordinates as arguments—you can then use the Y coordinate to either check that the cursor moved upwards by N pixels, or that it is above a certain line. Here is a simple trial illustrating how to update a Text element once the mouse has moved at least 50px north after clicking:
newTrial(
newButton("Start").print().wait().remove()
,
newVar("start_y", undefined)
,
newText("prompt", "Hello _____").print()
,
newMouseTracker("mouse")
.callback( async (x,y) => {
if (getVar("start_y").value === "stop") return;
else if (getVar("start_y").value === undefined)
await getVar("start_y").set(y)._runPromises();
else if (getVar("start_y").value - y > 50) {
await getVar("start_y").set("stop")._runPromises();
await getText("prompt").text("Hello World")._runPromises();
}
})
.start()
,
newButton("Finish").print().wait()
,
getMouseTracker("mouse").stop()
)
Jeremy