Go Down

Topic: Leonardo Mouse.move problem (Read 1 time) previous topic - next topic

Ovations

Hello Nick,

done.

I have spent several hours trying to fix my sketch but it seems to be impossible. Meanwhile I assume it is not my code doing strange things. It also seems that the glitches are bigger when the values given to Mouse.move() are higher.

I have re-programmed my original code with for-next and using small values for Mouse.move() but it is not very satisfying to have (small) manual corrections to give to the mouse cursor.

Best regards,

Chris

Nick Gammon

I think the problem is, mouse movements are accelerated. That is, they are non-linear. This is so if you move the mouse quickly it covers more ground than if you move it slowly. This modified sketch moves the mouse around in a square, and on my Mac at least, it arrives back at the exact same spot.

Code: [Select]
int buttonState;

void setup() {               
  pinMode(12, INPUT);
  digitalWrite(12, HIGH);
}

void loop() {
  int i;
  const int amount = 500;
 
  buttonState = digitalRead(12);

  if(buttonState == LOW){
    Mouse.begin();
    for (i = 0; i < amount; i++)
      Mouse.move(-1, 0, 0);

    delay(500);

    for (i = 0; i < amount; i++)
      Mouse.move(0, -1, 0);

    delay(500);

    for (i = 0; i < amount; i++)
      Mouse.move(1, 0, 0);

    delay(500);

    for (i = 0; i < amount; i++)
      Mouse.move(0, 1, 0);

    delay(2000);
    Mouse.end();
  }
}

Ovations

Hello Nick,

that's an idea - the mouse acceleration! I will check on that tomorrow and let you know.

Kind regards,

Chris

Ovations

Hello Nick,

thank you very much for your hint regarding mouse acceleration. This was causing the inaccuracy.
I just had to uncheck a box in the Windows mouse settings and update my sketch. It now exactly (!!!) does what I expected.

Kind regards,

Chris

LukeFrog


Hello Nick,

thank you very much for your hint regarding mouse acceleration. This was causing the inaccuracy.
I just had to uncheck a box in the Windows mouse settings and update my sketch. It now exactly (!!!) does what I expected.

Kind regards,

Chris



Hi Chris!

I am having this exact problem! What settings did you alter?

Regards,

Luke

Go Up