Absolute positioning of mouse cursor through button on the breadboard

Hi, I am developing a script for the mouse cursor control: I have to make the absolute movement of the cursor on the screen in a very precise position, starting from any position on the screen. I wrote this:

#include <MouseTo.h>

#include <Mouse.h>



int stato;
int button = 2;

void setup(){
pinMode(4, INPUT);
pinMode(button,OUTPUT);
}

void loop(){
stato=digitalRead(4);
int x;
int y;
if(stato== HIGH){
Mouse.begin();
digitalWrite(button,HIGH); 
for(int z = 1; z <= 10; z++){
x = random(0, 10);
y = random(0, 10);
 MouseTo.setTarget(x,y, true);}
delay(1000);

 } else {
  digitalWrite(button,LOW);
  Mouse.press();
}
Mouse.end();
}

The cursor doesn't move and I can't control it with the button on the breadboard

Your topic was MOVED to its current forum category as it is more suitable than the original as it is not an Introductory Tutorial

Which Arduino board are you using ?

arduino leonardo

more information is needed:

what exact type of microcontroller are you using?
Ah ok answered. Arduino Leonardo

Did you try some example-code that is distributed with the libraries you use?

it seems odd to call

Mouse.begin();
Mouse.end();

each time you want to do a mouse-move

You are talking about

but you use

x = random(0, 10);
y = random(0, 10);

how does using the random-function fit to precise position??
best regards Stefan

Hi, I'am using an arduino leonardo. Sorry for using random function, I have to use

moveTo.setTarget(x,y,true)

But also in this way it doesn't work

not clear what you're trying to do. a mouse is an input device. the cursor is an output on a screen

why do you use a hardcoded value here instead of defining it like button?

shouldn't a button be an INPUT?

what does "stato" represent?

shouldn't this be done once in setup()?

shouldn't you read a button?

why a 1 sec delay (is this how you avoid bounces?

So everything is clear now ? Or are there questions left open?

Have you ever heard of Autohotkey? Autohotkey can do much more than mouse-positioning

Start over with the "BasicUsage" example that comes with the MouseTo library.

You seem to be setting the target position but not actually telling the mouse to move to the target position:

    MouseTo.setTarget(0, 0);
    while (MouseTo.move() == false) {}

if absolute positioning is not available. Move into one edge of the screen 5000 pixels long
Then the mouse-arrow will be surely in the edge and then you can move again relative for a certain amout of steps and be sure that it is an absolute position
best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.