Open ubmay opened 4 years ago
I have a working implementation of JNativeHook and the robot class. I had to Split the JNativeHook into its own file and call it from within Main.
public class Global_Keyboard_Listener implements NativeKeyListener {
Global_Keyboard_Listener() {
}
public void setup() {
try {
GlobalScreen.registerNativeHook();
} catch (NativeHookException e) {
e.printStackTrace();
}
GlobalScreen.addNativeKeyListener(new Global_Keyboard_Listener());
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
Handler[] handlers = Logger.getLogger("").getHandlers();
for (int i = 0; i < handlers.length; i++) {
handlers[i].setLevel(Level.OFF);
}
}
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
}
@Override
public void nativeKeyReleased(NativeKeyEvent e) {
}
@Override
public void nativeKeyTyped(NativeKeyEvent e) {
}
}
Global_Keyboard_Listener listener = new Global_Keyboard_Listener();
Robot robot;
listener.setup();
while (true) {
try {
String foo = fun();
if (foo != null) {
robot = new Robot();
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
}
TimeUnit.MILLISECONDS.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}`
I have some code for an auto clicker I am making in java.
Running this script for a while disables mouse movement, hangs screen and pretty much disables all functions. MacOS Catalina 10.15.4