04-25-2022 12:13 PM
Is it possible to record mouse coordinate into array?
What I want to do :
- when I left click and hold the mouse, it start recording the mouse coordinate into an array (I'm thinking of using event structure to obtain mouse coordinate).
- when I release, it stops recording, and the next time mouse down event occurred, it will start putting mouse coordinate into the existing array.
Thanks in advance
Solved! Go to Solution.
04-25-2022 12:26 PM
Yes, that's easily possible. Is the mouse over any specific item (e.g. 2D image, graph, etc.) or the entire panel.
04-25-2022 12:53 PM - edited 04-25-2022 12:54 PM
See if this can give you some ideas.
(You definitely need to work out more details, this is just a very rough draft)
04-25-2022 01:10 PM
You can of course also simply record an array of points. It really depends what you need to do with it later.
(rest of the code stays basically the same)
04-26-2022 12:47 AM
This is what I tried before, there's 2 problems :
1. the dot only appears on the first click , but when I hold and drag to draw, it doesn't appear
2. the 1d elements into build array isn't accumulating, so it's only a 2x2 array forever , what I want is it keeps putting the coordinate inside the array
04-26-2022 01:20 AM
@PULSE.Wannabe wrote:
This is what I tried before, there's 2 problems :
1. the dot only appears on the first click , but when I hold and drag to draw, it doesn't appear
2. the 1d elements into build array isn't accumulating, so it's only a 2x2 array forever , what I want is it keeps putting the coordinate inside the array
1. Yes, Mouse down only activates once. Look at Altenbachs example, you need to use Mouse Move to collect more points.
2. Yes, look at what you're sending to the shift register, it's only the latest coords, not the resulting array.
04-26-2022 01:47 AM
ah yes I solved the 2nd problem, but for the 1st one, I want to click and hold and draw (recording coordinate from the moment I start to click and hold), then when I release, it stop recording, is it possible?
04-26-2022 09:41 AM
That's exactly what my code does. Mouse up/down events toggle the boolean so the state is available to all other event cases.
04-26-2022 10:23 AM
@PULSE.Wannabe wrote:
This is what I tried before, there's 2 problems :
1. the dot only appears on the first click , but when I hold and drag to draw, it doesn't appear
2. the 1d elements into build array isn't accumulating, so it's only a 2x2 array forever , what I want is it keeps putting the coordinate inside the array
Unfortunately, we cannot debug images, but there are serious flaws here. For example You read the mouse position way before the event even fires. You also have a glaring race condition dues to blatant overuse of local variables. None are needed. Your local gets read way before it gets written, so the display lags behind.
Thanks for pointing out that you are looking for mouse down event on a picture (not on the panel!). That makes things even easier.
04-26-2022 11:11 AM
See if this can give you some ideas....
(see attached VI for details. LabVIEW 2015)