How do I stop an EventHandler
? I'm trying to allow the user unlimited inputs on the arrow keys UNTIL certain conditions are met, and then stop the EventHandler
and move on to something else. How can I accomplish this?
I've tried:
EventHandler[
content,
{"LeftArrowKeyDown" :> ({ action; If[conditions, Abort[]];})
"RightArrowKeyDown" :> ({ action; If[conditions, Abort[]]; })
"UpArrowKeyDown" :> ({ action; If[conditions, Abort[]]; })
"DownArrowKeyDown" :> ({ action; If[conditions, Abort[]]; })
}]
But Mathematica seems to ignore the Abort[]
completely, though it will execute other commands within the If
statements when the same conditions are met. What am I missing here??
Edit: Okay, my code was rather general and unclear. Here is a more concrete example of what I want:
pt = {0.5, 0.5};
EventHandler[
Framed[Graphics[
{{Red, Disk[Dynamic[pt], .1]}},
PlotRange -> 1, Axes -> True
]],
{
"LeftArrowKeyDown" :> (
pt -= {0.05,0};
If[pt == {0, 0}, Abort[]]
),
"RightArrowKeyDown" :> (
pt +={0.05,0};
If[pt == {0, 0}, Abort[]]
),
"UpArrowKeyDown" :> (
pt +={0,0.05};
If[pt == {0, 0}, Abort[]]
),
"DownArrowKeyDown" :> (
pt -={0,0.05};
If[pt == {0, 0}, Abort[]]
)
}
]
So, my goal is to allow unlimited movement around this plane by the Disk, until the user moves the Disk to the point (0,0), at which time I want Mathematica to stop allowing input and move on to a different task in the code.
action
is take whetherconditions
are True or Note. Abort aborts only a specific evaluation and each event triggers another one. Do you want to disable an event completely after conditions are met? Or do you want to tak anaction
whenconditions
are True? Or maybe something different? $\endgroup$