Stop script running in the background after change window

Ask gaming related questions
idkwho
Posts: 2
Joined: 30 Jun 2018, 04:50

Stop script running in the background after change window

30 Jun 2018, 04:56

Hi I'm having problem with the script which still runs after I alt-tab and it affect my use in google chrome or other application. How can I make the script to only apply in game and disabled for example when I am using other applications? My game is running in borderless fullscreen if that makes any difference.

Thank you

Code: Select all

#SingleInstance,Force
#NoEnv
Auth_RunAsAdmin()
#MaxThreadsPerHotkey 1
#MaxThreads 200
SetWorkingDir %A_ScriptDir%
  
Auth_RunAsAdmin()
{
    Global
    If ( !A_IsAdmin ) {
        Loop, %0%  ; For each parameter
            sParams .= A_Space . %A_Index%
        Local ShellExecute
        ShellExecute := (A_IsUnicode) ? "Shell32.dll\ShellExecute" : "Shell32.dll\ShellExecuteA"
        A_IsCompiled
            ? DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,A_ScriptFullPath, Str,sParams , Str,A_WorkingDir, Int,1 )
            : DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,A_AhkPath, Str,"""" A_ScriptFullPath """ " sParams
                                , Str,A_WorkingDir, Int,1 )
        ExitApp
    }
}
 
/*
CURSORINFO
(
  DWORD   cbSize;       offset 0, size 4 bytes long
  DWORD   flags;        offset 4, size 4 bytes long
  HCURSOR hCursor;      offset 8, size 4-8 bytes long
  POINT   ptScreenPos; offset 12-16, size 8 bytes long
)"
Total size = (8 + 16) for 64bit or (4 + 16) for 32bit
*/
 
; We only care about if the mouse is hidden or not
; returns True if Hidden
isMouseHidden()
{
    ; struct to check mouse status (compatible with 32 or 64bits)
    c_msize := VarSetCapacity(g_mi, A_PtrSize + 16, 0)
    NumPut(c_msize, g_mi, "UInt") ; Set size of the struct
    DllCall("GetCursorInfo", "UPtr", &g_mi)
   
    return !NumGet(g_mi,  4, "UInt") ; mouse flags 0 == Hidden, >0 if not
}
 
; Hotkeys for game
#IfWinActive, Black Desert Online
{
    ^s::Suspend  

    LButton::
        if (isMouseHidden())
            send {Blind}{r down}
        else
            send {Blind}{click down}
    return
   
    ~LButton up::
        if (isMouseHidden())
            send {Blind}{r up}
        else
            send {Blind}{click up}
    return
       
    RButton::
        if (isMouseHidden())
            send {Blind}{t down}
        else
            send {Blind}{click down right}
    return
   
    ~RButton up::
        if (isMouseHidden())
            send {Blind}{t up}
        else
            send {Blind}{click up right}
    return
	

}
_3D_
Posts: 189
Joined: 29 Jan 2014, 14:40

Re: Stop script running in the background after change window

30 Jun 2018, 14:49

You need to check what is winactive() and do actions if your game is active.
AHKv2.0 use the future now.
idkwho
Posts: 2
Joined: 30 Jun 2018, 04:50

Re: Stop script running in the background after change window

30 Jun 2018, 16:13

I have used #IfWinActive, Black Desert Online however it still seems to work outside of the game for instance when I switch windows to Google Chrome and click one of the tabs it thinks that my mouse button is hold down and drags the tab. I'm confused on what I should change in my script to fix this issue.
_3D_
Posts: 189
Joined: 29 Jan 2014, 14:40

Re: Stop script running in the background after change window

30 Jun 2018, 23:40

https://autohotkey.com/docs/commands/_I ... m#Examples
* See in example:
#IfWinActive, yourGame ;block begin no {}
...
#IfWinActive ;block end

* Check what is the exactly name of yourGame executive (game.exe, loader.exe, somename.exe)
AHKv2.0 use the future now.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 22 guests