I have a Windows Forms application and I need to capture mouse movements outside of my window. My simplified code in my window class:
private void ButtonOnClick(object sender, EventArgs e)
{
Capture = true;
MouseMove += OnMouseMove;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
Console.Out.Write("!");
}
As you can see, when the user clicks the button, my program should start tracking the mouse (even if it is outside the window - this is the key task!) But I get really strange behavior. If I move the mouse inside the window, everything is fine ,! are written to the console. But when I move the mouse outside the window, only OnMouseMove is called only once (and the point is really outside). Then, if I move the mouse somewhere outside the window, it is no longer called. If I go back to the window, everything will be perfect. Go - 1 message, go to the window - OK.
Does anyone help?