Unfortunately, you do have to keep track of it yourself, but the good news is that its not hard.
The key is to create a global called mouse-was-down?
that is set to true if mouse-down?
was true in the last time your mouse-oriented procedure was called. Then mouse-clicked?
can be defined as follows:
to-report mouse-clicked?
report (mouse-was-down? = true and not mouse-down?)
end
It seems to work well in conjunction with a central mouse-management procedure that calls the other click-based procedures. For example:
globals [ mouse-was-down? ]
to-report mouse-clicked?
report (mouse-was-down? = true and not mouse-down?)
end
to mouse-manager
let mouse-is-down? mouse-down?
if mouse-clicked? [
add-turtle
; Other procedures that should be run on mouse-click
]
set mouse-was-down? mouse-is-down?
end
to add-turtle
crt 1 [ setxy mouse-xcor mouse-ycor ]
end
Using the mouse-is-down?
local variable keeps the behavior more consistent if the mouse button is released before mouse-manager
finishes.