0
votes

I'm trying to implement system-wide drag operation with middle mouse button. It should override middle mouse drag behavior in other programs. Currently, I am handling global mouse events with system-wide hooks.

Problem is - many programs still receive and handle same events like I did not intercept them.

Here's what I tried:

  • not call the next hook for mouse down event: I never receive mouse up, so I don't know where and when to stop dragging

  • not call the next hook for mouse move: cursor slows down tremendously

  • not call the next hook for mouse up: most windows in the system stop reacting to mouse events completely after my drag is finished

  • always call the next hook in the chain: if the control under mouse has scroll in it, most of the time it will be scrolling while my drag is in progress. Also UWP apps continue receiving mouse events during my drag, so if a link in MS Edge happens to be under cursor when it started, and mouse does not leave Edge boundary, Edge receives click event, and new tab is opened

What I need is: when user holds middle mouse and starts dragging, my drag handler should be called, and no other handlers, like file drag, scroll, etc should happen.

1
when you begin drag you need call SetCapture() and ReleaseCapture() when drag end. but not set any hooksRbMm
@RbMm Actually, I tried that. Problem is I need my drag to start from any application, not just from my own. I want to be able to drag any window in the system with middle mouse button form any point of that window, overriding any other behavior. Problem is, for example, that even if I call SetCapture after receiving the first MouseMove after mouse down, Microsoft Edge continues handling mouse movement by scrolling.LOST

1 Answers

0
votes

I ended up with somewhat hacky solution:

  • do not call the next hook for mouse down for middle button
  • record where it was pressed
  • when handling mouse up, if user did not drag - replay the whole mouse up + mouse down using SendInput from a separate thread (to avoid deadlock due to reentrancy)