From 805834d2b28ac663947637d1fc47eda6c883e13c Mon Sep 17 00:00:00 2001 From: Jared K Date: Wed, 2 Nov 2022 08:53:32 -0700 Subject: [PATCH 1/2] Check that lastID exists to prevent crash --- AFB.ahk | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/AFB.ahk b/AFB.ahk index a7c227e..aaec9be 100644 --- a/AFB.ahk +++ b/AFB.ahk @@ -3,13 +3,14 @@ /* constants */ -ONE_MIN := 1000 * 60 +ONE_MIN := 60 * 1000 THREE_MINS := 3 * ONE_MIN FIVE_MINS := 5 * ONE_MIN -SIXTEEN_MINS := 15 * ONE_MIN -DATA_DIR := A_WorkingDir . "\data" -RECONNECT_BUTTON_IMG := DATA_DIR . "\reconnect-button.png" -RECONNECT_TEXT_IMG := DATA_DIR . "\reconnect-text.png" +FIFTEEN_MINS := 15 * ONE_MIN + +DATA_DIR := A_WorkingDir . "\data" +RECONNECT_BUTTON_IMG := DATA_DIR . "\reconnect-button.png" +RECONNECT_TEXT_IMG := DATA_DIR . "\reconnect-text.png" RECONNECT_IMG_SEARCH_ARRAY := [RECONNECT_BUTTON_IMG, RECONNECT_TEXT_IMG] DirCreate(DATA_DIR) @@ -20,13 +21,13 @@ FileInstall("data\reconnect-text.png", RECONNECT_TEXT_IMG, 1) globals */ IsRunning := false -TrayTip("Script is ready for input. AntiKick is disabled.", "AwayFromBlox") +SetTrayTip("Script is ready for input. Anti-kick is disabled.") #MaxThreadsPerHotkey 2 F1:: { global IsRunning := !IsRunning If (IsRunning) { - TrayTip("AntiKick is enabled.", "AwayFromBlox") + SetTrayTip("Anti-kick is enabled.") } Else { Reload() } @@ -35,7 +36,7 @@ F1:: { lastID := WinGetID("A") robloxID := WinExist("Roblox") if (robloxID) { - ; BEGIN WORK + ; BEGIN WORK - any automation must be done between the BlockInputs BlockInput(True) WinActivate(robloxID) @@ -45,7 +46,9 @@ F1:: { BreakAFK() - WinActivate(lastID) + if (lastID) { + WinActivate(lastID) + } BlockInput(False) ; END OF WORK @@ -61,9 +64,14 @@ F1:: { Core logic for "breaking" afk idle timer */ BreakAFK() { + sleep(300) ; TODO allow action to be defined by user upon startup and/or config send("{Space down}") - sleep(100) + sleep(50) + send("{Space up}") + sleep(500) + send("{Space down}") + sleep(50) send("{Space up}") } @@ -78,8 +86,8 @@ Reconnect(winWidth, winHeight) { return 1 } } - } catch as exc { - MsgBox "Something went wrong when trying to check for reconnect button:`n" exc.Message + } catch as err { + MsgBox "Something went wrong when trying to check for reconnect button:`n" err.Message Reload } return 0 @@ -90,7 +98,7 @@ Reconnect(winWidth, winHeight) { (avg 9mins: 1/2 AFK timer - 1 (this is for redundancy)) */ GetIntervalMins() { - randomMins := Random(THREE_MINS, SIXTEEN_MINS) + randomMins := Random(THREE_MINS, FIFTEEN_MINS) return randomMins } @@ -119,4 +127,8 @@ ClickImageMidPoint(imageFile, xOffset, yOffset){ Click(clickX, clickY) sleep(350) Click(clickX, clickY) +} + +SetTrayTip(str, title := "AwayFromBlox") { + TrayTip(str, title) } \ No newline at end of file From 4705fa72b2fe17285c0d463a90658d3ac4e132fc Mon Sep 17 00:00:00 2001 From: Jared K Date: Wed, 2 Nov 2022 09:16:07 -0700 Subject: [PATCH 2/2] Add ahk v2 reminder at top --- AFB.ahk | 1 + 1 file changed, 1 insertion(+) diff --git a/AFB.ahk b/AFB.ahk index aaec9be..a611de8 100644 --- a/AFB.ahk +++ b/AFB.ahk @@ -1,3 +1,4 @@ +; AHK v2 #SingleInstance Force /*