Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I'm using my Arduino Leonardo as a Mouse but I'm experimenting a strange behaviour. I put my mouse at (-1, -1) (absolute) coordinates and then I execute this code:

Move.move(com[curr_cmd_id].x, com[curr_cmd_id].y, 0);

where that point is (334, 180) (relative coords) (and I checked it through Serial console)

Now, the pointer is actually moving to the right but then it stops. Let's say it reaches the point (334, 0).

Then I tried:

Mouse.move(com[curr_cmd_id].x, 0, 0);
delay(500);
Mouse.move(0, com[curr_cmd_id].y, 0);

but still the same behaviour.

Then finally I tried this one (which it actually solves my problem but it's a dirty solution):

int i;
for(i=0; i<com[curr_cmd_id].x; i++){
  Mouse.move(1,0,0);
  delay(1);
}
for(i=0; i<com[curr_cmd_id].y; i++){
  Mouse.move(0,1,0);
  delay(1);
}

Could anybody help me in understanding what's going on here? How can I achieve a simple and direct relative movement for my pointer? Thanks you in advance!!

share|improve this question
    
So it's only moving to the right, and not up? –  Gerben Aug 21 '14 at 15:38
    
Only on the right and not down (considering the coordinates I expect to go down with positive y) –  Rob013 Aug 21 '14 at 16:43
    
It looks like maybe there's something filtering a maximum "jump" in the mouse position. What happens if your increment your for loop by more than 1 - can you experimentally discover a limit? –  Chris Stratton Aug 22 '14 at 15:18

1 Answer 1

I struggled with this too until I realized this

Parameters

xVal: amount to move along the x-axis - signed char

yVal: amount to move along the y-axis - signed char

wheel: amount to move scroll wheel - signed char

Note it says signed char.

That means the value you pass to the Mouse.move is a signed 8-bit. (-128 to 127)

My work around is this below:

void moveMouse(int x, int y, int w){
  x = (int)x / 1.59; //Adjust these two values accordingly. I found out that 100, 100 does 
  y = (int)y / 1.58; //not move 100, 100. It moves 159, 158 for me.

  while(x!=0 || y!=0 || w!=0){
    int moveX, moveY, moveW;
    if(x > 0){
      if(x >= 100){
        moveX = 100;
      }else{
        moveX = x;
      }
    }else if (x < 0){
      if(x <= -100){
        moveX = -100;
      }else{
        moveX = x;
      }
    }else{
      moveX = 0;
    }

    if(y > 0){
      if(y >= 100){
        moveY = 100;
      }else{
        moveY = y;
      }
    }else if (y < 0){
      if(y <= -100){
        moveY = -100;
      }else{
        moveY = y;
      }
    }else{
      moveY = 0;
    }

    if(w > 0){
      if(w >= 127){
        moveW = 127;
      }else{
        moveW = w;
      }
    }else if (w < 0){
      if(w <= -128){
        moveW = -128;
      }else{
        moveW = w;
      }
    }else{
      moveW = 0;
    }

    x = x - moveX;
    y = y - moveY;
    w = w - moveW;

    Mouse.move(moveX, moveY, moveW);
  } 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.