ソースを参照

alfa.
not working in fullscreen
not working in minimized

ChesTeRcs 5 年 前
コミット
3e48975175
2 ファイル変更15 行追加7 行削除
  1. 14 7
      src/main/java/AntiAfk.java
  2. 1 0
      src/main/java/user32util/User32Util.java

+ 14 - 7
src/main/java/AntiAfk.java

@@ -31,20 +31,22 @@ public class AntiAfk {
         try {
             robot = new Robot();
 
-            do {
+            while (true) {
                 if (windowExists(windowTitle)) {
-
                     if (timeUntil.calcBetween(timeWhenAfkHappened) >= afkTimerInMs) {
-                        if (getActiveWindow().equals(getWindowPointer(windowTitle))) {
+                        if (getWindowPointer(windowTitle).equals(getActiveWindow())) {
                             antiAfk(antiAfkKey);
                         } else {
                             System.out.println("Need to tab");
                             Pointer lastWindow = getActiveWindow();
-                            setActivateWindow(windowTitle);
+                            if (!setActivateWindow(windowTitle)) {
+                                cantReachClient();
+                                continue;
+                            }
                             Thread.sleep(100);
                             antiAfk(antiAfkKey);
                             Thread.sleep(300);
-                            System.out.println(setActivateWindow(lastWindow));
+                            setActivateWindow(lastWindow);
                         }
                     }
 
@@ -54,12 +56,17 @@ public class AntiAfk {
                     System.out.println("Not running: " + windowTitle);
                 }
                 Thread.sleep(clock);
-            } while (true);
+            }
         } catch (AWTException | InterruptedException e) {
             e.printStackTrace();
         }
     }
 
+    public void cantReachClient() {
+        System.out.println("Can't reach client!");
+    }
+
+
     public boolean windowExists(String windowTitle) {
         return User32Util.windowExists(windowTitle);
     }
@@ -102,7 +109,7 @@ public class AntiAfk {
         if (winProcesstoBeActive == null) return false;
         try {
             Instant whenSettingStarted = timeUntil.getNowInInstant();
-            while (!getActiveWindow().equals(winProcesstoBeActive)) {
+            while (!(winProcesstoBeActive.equals(getActiveWindow()))) {
                 Thread.sleep(20);
                 if (timeUntil.calcBetween(whenSettingStarted) >= 8000) return false;
             }

+ 1 - 0
src/main/java/user32util/User32Util.java

@@ -79,6 +79,7 @@ public class User32Util {
     }
 
     public static boolean setForegroundWindow(Pointer hWnd) {
+        if (hWnd == null) return false;
         return USER_32_INSTANCE.SetForegroundWindow(hWnd) != 0;
     }