# Delay of events detection dependent of “MouseDown” position

Let's say we have a Rectangle with color which depends of CurrentValue["MouseOver"]:

Deploy@Framed@Graphics[
Dynamic @ {If[CurrentValue["MouseOver"], Red, Green], Rectangle[]}


• With cursor over the Rectangle[] the color switches to Red as expected,
• also if one put the "MouseDown" and drag it around it is still Red,
• however if you put the "MouseDown" outside the rectangle, on the padded area, and drag it to the rectangle it will not switch the color till "MouseUp".

Is there any way to avoid such behaviour in general?

I can create some workarounds for particular situations but I'm looking for a general solution. I was thinking about EventHandler's PassEvents options but it seems it is a deeper problem (I've failed with this approach :)).

It looks like the problem is the "MouseDown" event is blocking some functions, for example:

-
It doesn't switch until MouseMoved after MouseUp. It's as if MouseMoved and MouseDragged are mutually exclusive, and MouseOver is only updated on MouseMoved? –  Timothy Wofford Sep 30 '13 at 10:17
@TimothyWofford I do not see this, only MouseUp is enough for switch in my case, maybe it's OS dependent? It seems rather that MouseDown is blocking some events detections, try: Dynamic@CurrentValue["ControlKey"] and press Ctrl when the Mouse is down. –  Kuba Sep 30 '13 at 10:26
@Kuba I belive that dynamic interactivity in general is halted during mouse down, at least that has always been my experience (With slider interactions and such being excluded). For instance try DynamicWrapper[ Dynamic[t], Refresh[t = AbsoluteTime[], UpdateInterval -> 0.1] ], and press the mouse button. –  jVincent Sep 30 '13 at 10:37

When you press in the white area and drag into the green square, you begin a selection just like when you select objects for copy-paste operations. The workaround I propose is to prevent the selection process to begin in the first place.

First way: Create the cell with the option Selectable -> False

CellPrint@Cell[BoxData[ToBoxes@
Deploy@Framed@Graphics[
Dynamic@{If[CurrentValue["MouseOver"], Red, Green],
], Selectable -> False]


Second way: If the cell is already created, press Ctrl+Shift+E and edit the cell options to include Selectable -> False, press Ctrl+Shift+E again.

Update

The following code should produce the result you want:

CellPrint@Cell[BoxData[ToBoxes@
Framed@Graphics[
Dynamic@{If[CurrentValue["MouseOver"], Red, Green],

@Hector now it works :) thanks, it seems Deploy is messing around a little. –  Kuba Sep 30 '13 at 11:17
@Kuba: the strange thing is that Deploy is supposed to disable selection. –  Hector Sep 30 '13 at 11:18
@Kuba: I think the problem is that ContentSelectable -> False does not change the properties of the frame. –  Hector Sep 30 '13 at 11:22
@Hector It seems it is really what it is all about. It even helps with DynamicWrapper[ Dynamic[t], Refresh[t = AbsoluteTime[], UpdateInterval -> 0.1] ] –  Kuba Sep 30 '13 at 11:27