For example If the position of mouse in X coordinate is over 400 pixel then the robot will move the position of mouse to 350 pixel in X coordinate But the position of mouse in Y coordinate must not effected.
Because in the Robot class if I want to set the mouse position like this code
bot.mouseMove(350, 400);
In this code I have to set the Y position too. So I came up with some Idea like use the last position of Y in that code like this
void draw(){
if(mouseX<=5)
{
try
{
Robot bot = new Robot();
bot.mouseMove(420, mouseY);
}
catch (AWTException e)
{
e.printStackTrace();
}
}
}
But It's doesn't work. I think that's because "mouseY" is the position of mouse in the window But moseMove() will set the mouse according to the position of the monitor screen.
Please give me some suggestion and Thank you very much for your time.
With java.awt.MouseInfo - getPointerInfo()
Returns a PointerInfo instance that represents the current location of the mouse pointer.[...]
You can use this to read current Y position and change just the X value. You can also change following code to change just the Y position.
import java.awt.MouseInfo;
and then try:
bot.mouseMove(420, MouseInfo.getPointerInfo().getLocation().y);
For your code, something like this:
call draw(SOMEVALUE, MouseInfo.getPointerInfo().getLocation().y);
void draw(int mouseX, int mouseY){
if(mouseX<=5)
{
try{
Robot bot = new Robot();
bot.mouseMove(420, mouseY);
}catch (AWTException e){
e.printStackTrace();
}
}
}