Arduino absolute Positioning

Hi all,
I'm trying to make an arduino absolute positioning mouse but something is wrong with my code. When I upload this code it doesn't do anything. I'm using arduino leonardo micro and MouseTo.h library.

#include <MouseTo.h>

#include <Mouse.h>
int pin = 2;
void setup(){
  pinMode(pin,INPUT);
  
  Mouse.begin();
  
  MouseTo.setScreenResolution(800, 700);
 
 
}

void loop(){
 if(pin == HIGH){
MouseTo.setTarget(400, 100);
 }
   
  //delay(1000);
}

if(pin == HIGH){Two never equals one.

Must be about the third time this week - a new record?

If I delete if() then against then same

Maybe you should fix the error, rather than delete the line?

It seems strange that pin is set to INPUT rather than INPUT_PULLUP, but without a wiring diagram, who knows?

Also, instead of deleting the "if", fix it. Shouldn't there be a digitalRead somewhere?

you are right about digitalread. I didn't copy paste right the code also I think it's a problem on format of library that I cant find it

I didn't copy paste right the code

Why not write your own code, so that you actually understand it?

I found an examle but I can't understand MouseTo.setTarget(x,y) function. If I remove the second while then it doesn't works. If I use thiw code then cursor goes to (400,100) on screen then after 1 second it returns on (0.0) and then again on (400,100)
thanks for your help

#include <Mouse.h>

#include <MouseTo.h>

const byte pin = 6;

void setup() {
  Mouse.begin();
  MouseTo.setCorrectionFactor(1);
  MouseTo.setScreenResolution(800,800);
  pinMode(pin, INPUT_PULLUP);
}

void loop() {
  while (digitalRead(pin) == LOW) {
    MouseTo.setTarget(400, 100);
    while (MouseTo.move() == false) {}
    delay(1000);
  
     }
}

If I remove the second while then it doesn't works.

Then the second "while" is probably doing something important. Can you guess what that might be?

Better yet, what does the mouse program library documentation have to say about the function MouseTo.move()?

--MouseTo.move()

Move mouse pointer to the target coordinates. Multiple calls to MouseTo.move() may be required before the target coordinates are reached.

Returns: true = target coordinates reached, false = target coordinates not yet reached

--MouseTo.setTarget(targetX, targetY[, homeFirst])

Move mouse pointer to absolute screen coordinates. Note that screen coordinates start from the upper left corner.

Parameter: targetX - X screen coordinate to move to.
Type: int
Parameter: targetY - Y screen coordinate to move to.
Type: int
Parameter(optional): homeFirst - Whether to home the mouse pointer before moving to the target. At a minimum the pointer must be homed before the first use of MouseTo in your code. If homing is not done after that time the accuracy of the mouse pointer movements might suffer, for example if the regular mouse connected to the computer is moved. The default value is true.
Type: boolean
Returns: none

Excellent! Now do you understand why that "while" statement is important?