Jump to content

Mouse Capture


Recommended Posts

Hi all!

How do you implement mouse capture for controls? This is more of a philosophical question about your solutions, you did you learn to live without it etc.

By mouse capture I mean mouse capture:
A control receives mouse events even if the pointer is not above the control. It's useful for dragging among controls, or for a graphical user interface (mousedown>mousemove>mouseup event chain). Without mouse capture if the user accidentally leaves the drawing area during a drag-like operation and mouseup occurs outside, the drawing area gets stuck in dragging mode (mostly). This is a very annoying phenomenon.
However, this is usually only needed in 1-2 controls (or 0 in most cases), so obviously not for everything you have on the front panel.

Mousecapture in win32 programming is very easy. You call Setcapture(control_handle) on mousedown, and call releasecapture() on mouseup. It does have problems (system releases capture because another window gets on top for whatever reason), but these can be handled. And usually the problems are not that severe, or at least doesn't happen whenever the user moves the mouse too fast…

So how to deal with it in Labview?

  • No, calling the winapi with setCapture won't work as it works with windows (win32 treats controls as windows) but in Labview by default there is only one window: the front panel.
  • Somehow replacing drag+drop functions all controls have some sort of?
  • Creating user events for mouse handling and all controls have to handle mouse events and propagate them to the user event?
  • Somehow make the control you want to mousecapture a separate window but mimic it's not? +winapi
  • Some mouseleave/mouseenter hack and checking button states (but how? you shouldn't mix events with polling)?
  • Ditch event structure and go for polling? Or even worse: polling only the mouse in a separate loop and generate user events?
  • Some special control (ActiceX?) that has mousecapture using function that's easy to replace and place it invisibly on to of your control?
  • Confine the cursor to the control (that's the worst one yet…)
  • other...

Thanks for any hints and ideas or stories on the topic and sorry for the inaccuracies in technological terms, it was very long ago when I did win32 programming.

Link to comment

I'm not sure I understand what you're asking, but have you looked at the "Input Device Control" VIs? See the example "Monitoring Keyboard and Mouse Activity.vi"

National Instruments\LabVIEW 20XX\examples\Connectivity\Input Device Control\Monitoring Keyboard and Mouse Activity.vi

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.