Chappie74 / flutter_auto_gui

Dart project that allows you to control the mouse and keyboard to automate interactions with other applications.
10 stars 6 forks source link

[BUG] moveTo move mouse cursor to wrong position #1

Closed PepeExpress closed 2 years ago

PepeExpress commented 2 years ago

I'm trying to use the moveTo method but seems like the pointer is moved to a wrong position. This is the method I use to update the mouse cursor position:

  Future<void> moveCursor() async {
    Point<int>? position = await FlutterAutoGUI.position();
    Point<int> newPosition = Point(10 + position!.x, 10 + position.y);
    await FlutterAutoGUI.moveTo(point: Point(newPosition.x, newPosition.y));
    Utility.logger.i("Old mouse position was: $position | New position should be $newPosition");
  }

If I call this method twice this is the output I get:

Old mouse position was: Point(2414, 376) | New position should be Point(2424, 386)
Old mouse position was: Point(2272, 381) | New position should be Point(2282, 391)

In the second log the mouse position is not what should be as pointed out in the first log (the new mouse position should be 2424, 386 but instead is 2272, 381

PepeExpress commented 2 years ago

I opened this PR that should resolve the problem @Chappie74

Chappie74 commented 2 years ago

Thank you for your contribution.

I'd like to ask (just to up my experience), how were you able to determine it was precision issue with the division? I don't think I would have ever realised this was the issue if I were trying to solve this on my own.

PepeExpress commented 2 years ago

Thank you for setting up this project. To find out what was wrong I just debugged the plugin code and since the dart part looked good I started to debug the native code and noticed that the normalized value of x and y weren't the ones I was expecting. Since I have no experience with C++ I was lucky finding a similar problem googling around! It's strange tho that the y value is still off by 2 pixel, later I will try to see if I can fix that too and I will update the PR

Chappie74 commented 2 years ago

Ahhh gotcha. Thanks again for finding this. I'll look out for the updated PR.

Chappie74 commented 2 years ago

Fixed with PR