How to detect when mouse move has stopped

I’d like to do something when the mouse moves, but just when it has stooped, not while it is moving.

I imagine how to do it with a timer, but can you imagine another and better approach to it?

The action that has to be performed will take some time, so it is a pity to repeat it many times when the mouse is moving, if I only want to do it at the end or when the mouse is quiet for a moment.

TIA

best you can do is

  1. create a timer
  2. everytime the mouse moves, reset the timer
  3. when timer finally fires, this means the mouse has not moved for the period of the timer

And what are you going to do if the mouse starts moving during the process ?

Well. Perhaps I should explain the situation better.
I have a graphic with many lines representing cables, ropes, bars, etc. There are also triangles, geodesic lines, auxiliary lines and nodes. When the mouse pointer hovers over them the single object with the mouse on highlights. But this has a computing cost.
Now, while I move the mouse, some of these elements highlight on and off. It depends on the number of objects and the computing cost. But I’m only really interested in highlighting the last one: when the mouse pointer stops.

Is it clearer now?
I don’t know how to explain it better in a few words.

Don’t restart the timer until the process completes

or do this…

  1. Mouse is over Object X
  2. if the last object = Object X?
  3. if YES then 2
  4. Unhighlight last object highlighted
  5. Highlight Object X

this way objects are selected only when they “get focus”

Thanks Dave.

The problem is that the computing cost is knowing which object is under the pointer. Not highlighting it on/off.

I was thinking of something like this:

  1. when mouse move:
  • a timer (very short period) is reset “only” if it is in mode off
  • x,y values of mouse position are saved for the timer
  1. In the timer action
  • there is a pair of values x0,y0 as local static values
  • if the two pair of values (x,y and x0,y0) are different it means that the mouse is moving --> update x0/y0 and do nothing else
  • if values are practically equal (1 or 2 pixels) I suppose that the mouse has stopped:
    · stop timer (mode off)
    . do highlighting

This is what I’ve though, but I need a very short period timer on and I don’t know if this is going to slow the whole process more than the computing cost to know which object is highlighted.

I know that it doesn’t exist, but what I’d need is an Event “mouseStopped” :slight_smile:

[quote=201245:@Ramon SASTRE]Thanks Dave.

The problem is that the computing cost is knowing which object is under the pointer. Not highlighting it on/off.

I was thinking of something like this:

  1. when mouse move:
  • a timer (very short period) is reset “only” if it is in mode off
  • x,y values of mouse position are saved for the timer
  1. In the timer action
  • there is a pair of values x0,y0 as local static values
  • if the two pair of values (x,y and x0,y0) are different it means that the mouse is moving --> update x0/y0 and do nothing else
  • if values are practically equal (1 or 2 pixels) I suppose that the mouse has stopped:
    · stop timer (mode off)
    . do highlighting

This is what I’ve though, but I need a very short period timer on and I don’t know if this is going to slow the whole process more than the computing cost to know which object is highlighted.

I know that it doesn’t exist, but what I’d need is an Event “mouseStopped” :-)[/quote]

This looks good. In my experience, 20 ms is often quite enough for such a thing.

I doubt very much a simple timer that checks on the value of x and y is more processing than what you do to track the position of objects.

I just tried something else, that looks much more like a MouseStop event :

  • Add a Timer to the page (here Timer1)
  • In MouseMove :

Sub MouseMove(X As Integer, Y As Integer) Timer1.enabled = False Timer1.Mode = Timer.ModeSingle Timer1.Period = 100 Timer1.Enabled = True End Sub

  • In Timer1.Action :

Sub Action() // Do whatever is needed in MouseStop TextArea1.Text = Textarea1.Text + "Mouse stop"+EndOfLine TextArea1.SelStart = TextArea1.Text.Len me.enabled = False End Sub

I originally set the timer period to 20, and it was firing all the time. With 100 (1/10th a second), it seems to be much better suited to detect when the mouse stops for a human being.

The nice thing here is that the timer does not fire constantly, but only when the mouse actually stops, and there is no need to keep track of x and y.

I like this idea.
I’ll check it.
Thank you very much.