Fix Command F7 #SingleInstance, Force
#MaxThreadsPerHotkey 2

SetTitleMatchMode, 2
SetKeyDelay, -1
CoordMode, Mouse, Screen

Global primaryMonitorWidth := 1920   ; Width of primary monitor
Global secondMonitorWidth := 1920    ; Width of second monitor
Global secondMonitorHeight := 1080   ; Height of second monitor
Global screencenterx := -(secondMonitorWidth // 2)   ; Center x of the second monitor to the left
Global screencentery := (secondMonitorHeight // 2)   ; Center y of the second monitor

F5::
Goto AFKCTest

F6::
ToolTip, GeForceNow Anti-AFK Enabled, 0, 0
Goto GeForceNowAntiAFK

F7::
Goto ContinuousEKey

F8::
Goto MetalRun

F9::
Goto StoneRun

F10::
Goto CrystalRun

F11::
Goto WoodRun

AFKCTest:
AFKCToggle := !AFKCToggle
loop
{
    If not AFKCToggle
        break
    Sleep 100
    ControlClick, x%screencenterx% y%screencentery%, GeForce NOW,,,, D Pos
    ControlClick, x%screencenterx% y%screencentery%, GeForce NOW,,,, U Pos
}
return

GeForceNowAntiAFK:
Gui, Submit, NoHide
SetTimer, GeForceNowAntiAFKLoop, 240000
return

GeForceNowAntiAFKLoop()
{
    WinGetPos, X, Y, Width, Height, GeForce NOW
    if ErrorLevel = 0
    {
        WinMove, GeForce NOW,, X, Y + 1
        Sleep, 333
        WinMove, GeForce NOW,, X, Y
    }
}

ContinuousEKey:
    EKeyToggle := !EKeyToggle
    loop
    {
        If not EKeyToggle
            break
        Send, e
        Sleep, 100
    }
return

MetalRun:
    ; Activate GeForce NOW window
    WinActivate, GeForce NOW                       
    Sleep, 300  ; Small delay to ensure activation

    ; Perform actions using Send
    Send, f
    Sleep, 300
    MouseClick, Left, -650, 200
    Sleep, 100
    Send, g
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, R
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, o
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, h
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, f
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    
    Send, {Esc}
    Sleep, 100
    
    MouseClick, Left, 1250, 200

    ; Return to primary monitor and activate "ARK: Ascended"
    primaryMonitorCenterX := 1920 // 2
    primaryMonitorCenterY := 1080 // 2
    MouseMove, %primaryMonitorCenterX%, %primaryMonitorCenterY%, 0
    WinActivate, ArkAscended
Return

StoneRun:
    ; Activate GeForce NOW window
    WinActivate, GeForce NOW                       
    Sleep, 300  ; Small delay to ensure activation

    ; Perform actions using Send
    Send, f
    Sleep, 300
    MouseClick, Left, -650, 200
    Sleep, 100
    Send, d
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, g
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, h
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    Send, {Esc}
    Sleep, 100
    
    MouseClick, Left, 1250, 200

    ; Return to primary monitor and activate "ARK: Ascended"
    primaryMonitorCenterX := 1920 // 2
    primaryMonitorCenterY := 1080 // 2
    MouseMove, %primaryMonitorCenterX%, %primaryMonitorCenterY%, 0
    WinActivate, ArkAscended
Return



ContinuousEKey:
    EKeyToggle := !EKeyToggle
    loop
    {
        If not EKeyToggle
            break
        Send, e
        Sleep, 100
    }
return

CrystalRun:
    ; Activate GeForce NOW window
    WinActivate, GeForce NOW                       
    Sleep, 300  ; Small delay to ensure activation

    ; Perform actions using Send
    Send, f
    Sleep, 300
    MouseClick, Left, -650, 200
    Sleep, 100
    Send, E
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, o
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, f
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, h
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100
    
    Send, {Esc}
    Sleep, 100
    
    MouseClick, Left, 1250, 200

    ; Return to primary monitor and activate "ARK: Ascended"
    primaryMonitorCenterX := 1920 // 2
    primaryMonitorCenterY := 1080 // 2
    MouseMove, %primaryMonitorCenterX%, %primaryMonitorCenterY%, 0
    WinActivate, ArkAscended
Return

WoodRun:
    ; Activate GeForce NOW window
    WinActivate, GeForce NOW                       
    Sleep, 300  ; Small delay to ensure activation

    ; Perform actions using Send
    Send, f
    Sleep, 300
    MouseClick, Left, -650, 200
    Sleep, 100
    Send, R
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    MouseClick, Left, -650, 200
    Sleep, 100
    Send, H
    Sleep, 100
    Send, {Enter}

    MouseClick, Left, -500, 193
    Sleep, 100
    Send, {Enter}
    Sleep, 100

    Send, {Esc}
    Sleep, 100
    
    MouseClick, Left, 1250, 200

    ; Return to primary monitor and activate "ARK: Ascended"
    primaryMonitorCenterX := 1920 // 2
    primaryMonitorCenterY := 1080 // 2
    MouseMove, %primaryMonitorCenterX%, %primaryMonitorCenterY%, 0
    WinActivate, ArkAscended
Return

F12::
    ; Get the process ID of the current script
    Process, Exist
    currPID := ErrorLevel
    
    ; Get a list of all AutoHotkey script windows
    WinGet, winList, List, ahk_class AutoHotkey

    ; Loop through each window handle
    Loop, %winList%
    {
        thisID := winList%A_Index%
        WinGet, thisPID, PID, ahk_id %thisID%
        
        ; If this process is not the current script, terminate it
        if (thisPID != currPID)
        {
            Process, Close, %thisPID%
        }
    }
return