From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster follows mouse when mouse is clicked and moves

Solved!
Go to solution

Hello, I am creating an interface through SubVIs inside a cluster with a title and I'm trying to reproduce a "window move" effect when the mouse is clicked and moves through the window title (a string inside my cluster). It works already pretty good but when the mouse moves too quickly the window can't follow the mouse and loses the position ("mouse leave" event).

Can you suggest me a more efficent way to do this?

I attach a simplified version of my VI with only one cluster that can move through my front panel.

I hope you can help me, thanks in advance

Dario

0 Kudos
Message 1 of 10
(2,949 Views)
  • All your type definitions are missing. Please attach them.
  • I would use shift registers to keep the state data (clicked, start coords, etc.), not disconnected controls/indicators.
  • You don't need the timeout event, but you need an event for the stop button.
0 Kudos
Message 2 of 10
(2,935 Views)

I tried doing something similar using an all event method but I found that it had similar limitations to what you are finding. I was moving the entire window though, not things inside the window. I ended up watching for the mouse button release in the timeout instead of hoping for the event (this requires remembering if the button is pressed). I used the Acquire Input Data vi to get mouse information. Perhaps there is a reliable way to do this with events but I couldn't get it to work as well as I would have liked. To not miss clicks and update the window or cluster smoothly, you obviously need the timeout event to run pretty often. Like 1ms or something. I think you can get away with 10ms but it just looks more choppy. Generally though, you want to limit your busy waiting since it eats up CPU cycles.

0 Kudos
Message 3 of 10
(2,920 Views)

Sorry, I attach a VI with your suggestions (shift registers, stop event). Unfortunately this does not solve my problem 😞

 

Using the "Register Mouse Event" in the timeout event is way too CPU heavy (most of the time the user does not want to move the window).

 

One solution that I tried was to brutally slow down the speed of the mouse when i detect the mouse click so that the mouse can't go out of the window (no "mouse leave" event) but I found this solution not really elegant (I had to call a windows DLL to change the mouse speed). I attach this version too

 

Do you have other ideas?

Download All
0 Kudos
Message 4 of 10
(2,893 Views)
Solution
Accepted by topic author cassaniti

Okay I think your problem is a little different than mine was (since it was an issue when I lost the mousemove when it left the pane). I think this should be good for you.

Message 5 of 10
(2,883 Views)

Wow that's cool! I'm not familiar with the feedback node, I'll try to understand how it works and apply it to my code! Thanks a lot!

0 Kudos
Message 6 of 10
(2,876 Views)

Honestly, I very rarely use it. I just wanted to quickly debug the events. I think the better practice is to bundle all of your wires into a cluster and use the feedback terminal at the while or for loop like you were doing. But since you didn't have a cluster set up, I was lazy and just used a feedback node.

0 Kudos
Message 7 of 10
(2,870 Views)

The most important thing is probably that you don't lock the front panel for the mouse move event and set the event queue size to 1.

 

MouseMove.png

Message 8 of 10
(2,868 Views)

Unfortunately what I uploaded was a "simplified example", but in my original application all the "windows move" events are controlled by a Dynamic Event, where I don't have the "Limit maximum instances of this event in the event queue".

In any case i find that the last version that you uploaded has the same issues that my version had (when the mouse moves to fast it loses grip on the window move event), but the previous version didn'tMouseMove.PNG

0 Kudos
Message 9 of 10
(2,843 Views)

Anyway what did the trick for me was to use the event "Mouse Move" on the whole FrontPanel and not on the DeviceName of the cluster (WindowTitle) as shown in the example you posted above. In this way I always have the coordinates of my mouse while the mouse left button is pressed.

0 Kudos
Message 10 of 10
(2,839 Views)