I would like to write a simple code that samples mouse position as frequently as the system can handle (with minimum dt) starting when the mouse position leaves a region and ending when the mouse position enters a different region. Without the regions, this is done simply by
pointlist = {};
dt = 1/100; (*max 1/dt samples per second *)
total = 4; (*total time in seconds *)
starttime = AbsoluteTime[];
Do[
AppendTo[pointlist, Flatten@{AbsoluteTime[], MousePosition[]}];
Pause[dt];
, {i, total/dt}];
Looking through MousePosition[]
and MouseOver[]
documentation it seems that there should be a way to use EventHandler[]
but the examples and actions seem graphically based. And while statements like
If[CurrentValue["MouseOver"], 0, 1]
seem like they should work, I get nothing when I put it into a While loop:
pointlist = {};
dt = 1/100; (* 1/dt samples per second *)
starttime = AbsoluteTime[];
While[
Dynamic[If[CurrentValue["MouseOver"], "A", "B"] == "B"],
AppendTo[pointlist, Flatten@{AbsoluteTime[], MousePosition[]}];
Pause[dt];]
Essentially, I want for regions A and B
While[MousePosition[] \nin A \cup B, AppendTo[pointlist, Flatten@{AbsoluteTime[], MousePosition[]}];
Pause[dt]; ]
where \nin is the usual "not in" and "cup" is the usual union. Once this mechanism is worked out, I can add my own bells and whistles.