0

I am trying to write a program in which a user can create a script of clicks and key presses, and execute them in order. The most important feature of this program is being able to accurately place clicks on proper coordinates on screen. I made this program a year ago in C#, but now I am retrying it in JavaFX so that it is prettier. I am using JNativeHook for key listeners and mouse listeners.

Here is the issue I am facing: When running robot.mouseMove(), the cursor is sent to a completely random location on screen. I am verifying this by outputting the current location of the cursor both inside of the NativeMouseListener mousePressed function, and inside of the class with robot. To get the mouse position in NativeMouseLIstener, I am using NativeMouseEvents getX and getY functions, which are completely accurate. Then for the other output, I am using PointerInfo.getPointerInfo() which has varying result. When the display DPI scaling is set to 100%, PointerInfo is completely inaccurate. It seems kind of absurd. Robot is sending the mouse ro a random location, and PointerInfo can't even read the location right. If I set the display scaling to 125%, then PointerInfo will get the same location on screen as NativeMouesListener, but the problem with robot still exists.

Are there any alternatives or external libraries I can use to simulate mouse clicks? It is unbelievable that something as dysfunctional as robot is the only thing we have to accomplish this.

Here is a video further explaining my problem: https://www.youtube.com/watch?v=BerTofDwRUw

luator
  • 4,769
  • 3
  • 30
  • 51
Connor S
  • 353
  • 2
  • 12

1 Answers1

0

Why do yo even need external libraries. You can use the AWT Robot to move the mouse and simulate mouse clicks and key presses. https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

RalleYTN
  • 138
  • 10