-3

I started to write a dynamic balancing software and the mouse that I want to move infinitely will be acting as a sensor to read the revolutions of the motor shaft. Basically I'll point the laser to the motor shaft and while the shaft is spinning the software will calculate the RPM. (I'm not talking about the accelerometers).

The MouseMove event is triggered only if the cursor is within the screen but I want to create an infinite (invisible) area that I can move the mouse. The Location will reach to millions or even billions but that's what I want. How can I do that?

Best, Suat

Suat
  • 11
  • 2
  • 1
    ?????????????????????????? – TaW Oct 23 '14 at 17:43
  • 2
    Why would you want your mouse (which is an input device needed for the GUI) to go outside your screen where there is no GUI?? – Jean-François Côté Oct 23 '14 at 17:45
  • Put the additional information etc into the question itself (click in the Edit link) and it may get reopened. See http://stackoverflow.com/help/how-to-ask – Stephen Kennedy Oct 23 '14 at 18:18
  • So the mouse events may not be to solve my problem. Maybe a way to connect to the mouse physically and read directly the laser sensor? – Suat Oct 23 '14 at 18:39

1 Answers1

0

To achive an infinite moving, you could relocate the cursor to the opposite screen's side, when it reaches one:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    // This method should only work when the mouse is captured by the Form.
    // For instance, when the left mouse button is pressed:
    if ((e.Button & MouseButtons.Left) == 0)
        return;

    Point p = PointToScreen(e.Location);
    int x = p.X;
    int y = p.Y;
    Rectangle bounds = Screen.PrimaryScreen.Bounds;

    if (x <= bounds.Left)
        x = bounds.Right - 2;
    else if (x >= bounds.Right - 1)
        x = bounds.Left + 1;

    if (y <= bounds.Top)
        y = bounds.Bottom - 2;
    else if (y >= bounds.Bottom - 1)
        y = bounds.Top + 1;

    if (x != p.X || y != p.Y)
        Cursor.Position = new Point(x, y);
}
Dmitry
  • 13,797
  • 6
  • 32
  • 48