Help, ive tried several things but i cant find the right solution

Ask gaming related questions (AHK v1.1 and older)
EmileWolf
Posts: 5
Joined: 13 Jan 2022, 09:42

Help, ive tried several things but i cant find the right solution

Post by EmileWolf » 18 Jan 2022, 17:17

What I need:
I want to loop pressing w and s infinitely (each press can last about a couple of milliseconds) with a small-time between each press but I need it to happen whilst my other loops are happening, so basically it should be independent of the entire script, or having that action happen in a completely different script but I need it to activate with a hotkey if possible ctrl+alt+z.

This is the script, I know its long but it does exactly what I need to do.
--------------------------------------------------------------------------------------------------------------------

Code: Select all

Menu, Tray, NoIcon

#SingleInstance, force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, Add, Edit, x42 y109 w120 h20 vPressTimeAD gActivation,
Gui, Add, Edit, x42 y139 w120 h20 vPressTimeW gActivation,
Gui, Add, Edit, x42 y169 w120 h20 vDestroyButton gActivation,
Gui, Color, black
Gui, Font, S8 CWhite, Verdana
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S16 CDefault, Asinastra
Gui, Font, S14 CDefault, Asinastra
Gui, Font, S20 CWhite, Asinastra
Gui, Add, Text, x48 y19 w350 h30 +Center, Pigeon's netherwart script
Gui, Font, S18 CWhite, Asinastra
Gui, Add, GroupBox, x562 y-1 w-30 h170 , GroupBox
Gui, Font, S16 CWhite, Asinastra
Gui, Add, GroupBox, x28 y69 w390 h150 , Config
Gui, Font, S14 CWhite, Asinastra
Gui, Add, Text, x192 y139 w190 h30 , W press time
Gui, Add, Text, x192 y169 w210 h30 , Attack/destroy button
Gui, Add, Text, x192 y109 w190 h30 , AD press time
Gui, Font, S18 CWhite, Asinastra
Gui, Add, GroupBox, x28 y239 w390 h170 , Info
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S16 CDefault, Asinastra
Gui, Font, S14 CDefault, Asinastra
Gui, Font, S18 CBlack, Asinastra
Gui, Font, S12 CWhite, Asinastra
Gui, Add, Text, x322 y429 w120 h30 , 1000-7 im ghoul
Gui, Font, S16 CWhite, Asinastra
Gui, Font, S14 CWhite, Asinastra
Gui, Font, S14 CWhite, Asinastra
Gui, Add, Text, x42 y309 w360 h30 , Script from discord.gg/S2tYVMNxNM
Gui, Add, Text, x42 y349 w330 h30 , ctrl+alt+q - script activation
Gui, Add, Text, x42 y269 w190 h30 , F9 - exit
Gui, Add, Text, x232 y269 w170 h30 , F10 - reload
; Generated using SmartGUI Creator 4.0
Gui, Show, x304 y107 h488 w451, New GUI Window
Return

Activation:
Gui, Submit, NoHide

!^q::

#Persistent
SetTimer, Infinite, 50
Return

Infinite:
ControlSend,, ws, ahk_exe javaw.exe
Return

Loop
{

;main part
 ControlSend,, {%DestroyButton% down}, ahk_exe javaw.exe

Loop, 3
{
 sleep 100

 ControlSend,, {d down}, ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down}, ahk_exe javaw.exe
 sleep 100
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down} , ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {a up}, ahk_exe javaw.exe

 Loop, 12
 {

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down} , ahk_exe javaw.exe
 sleep 100
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down}, ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down}, ahk_exe javaw.exe
 sleep 100
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down} , ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 }
}

Loop, 3
{
 sleep 100

 ControlSend,, {a down} , ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down} , ahk_exe javaw.exe
 sleep 100
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down}, ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 Loop, 12
 {

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down}, ahk_exe javaw.exe
 sleep 100
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {a down} , ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {a up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down} , ahk_exe javaw.exe
 sleep 100
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {w down}, ahk_exe javaw.exe
 sleep 400
 ControlSend,, {w up}, ahk_exe javaw.exe

 sleep 100

 ControlSend,, {d down}, ahk_exe javaw.exe
 sleep %PressTimeAD%
 ControlSend,, {d up}, ahk_exe javaw.exe

 sleep 100
 }
}
}


F9::ExitApp
F10::Reload

GuiClose:
GuiEscape:
ExitApp
return
[Mod edit: [code][/code] tags added.]
------------------------------------------------------------------------------------------------------------

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Help, ive tried several things but i cant find the right solution

Post by mikeyww » 18 Jan 2022, 17:41

I'd go with this: viewtopic.php?p=438911#p438911. You can always add a hotkey to it if needed.

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Help, ive tried several things but i cant find the right solution

Post by Xtra » 18 Jan 2022, 18:13

I simplified your script with one function that cuts the script size in half.
You should be able to run a timer and the loops at the same time. If you have an issue with timing you can always run the timer part in its own script like mikey posted.

Code: Select all

Menu, Tray, NoIcon
#Persistent    ; Note: A gui makes the script persistent so not really needed
#SingleInstance, force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, Add, Edit, x42 y109 w120 h20 vPressTimeAD gActivation,
Gui, Add, Edit, x42 y139 w120 h20 vPressTimeW gActivation,
Gui, Add, Edit, x42 y169 w120 h20 vDestroyButton gActivation,
Gui, Color, black
Gui, Font, S8 CWhite, Verdana
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S16 CDefault, Asinastra
Gui, Font, S14 CDefault, Asinastra
Gui, Font, S20 CWhite, Asinastra
Gui, Add, Text, x48 y19 w350 h30 +Center, Pigeon's netherwart script
Gui, Font, S18 CWhite, Asinastra
Gui, Add, GroupBox, x562 y-1 w-30 h170 , GroupBox
Gui, Font, S16 CWhite, Asinastra
Gui, Add, GroupBox, x28 y69 w390 h150 , Config
Gui, Font, S14 CWhite, Asinastra
Gui, Add, Text, x192 y139 w190 h30 , W press time
Gui, Add, Text, x192 y169 w210 h30 , Attack/destroy button
Gui, Add, Text, x192 y109 w190 h30 , AD press time
Gui, Font, S18 CWhite, Asinastra
Gui, Add, GroupBox, x28 y239 w390 h170 , Info
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S20 CDefault, Asinastra
Gui, Font, S16 CDefault, Asinastra
Gui, Font, S14 CDefault, Asinastra
Gui, Font, S18 CBlack, Asinastra
Gui, Font, S12 CWhite, Asinastra
Gui, Add, Text, x322 y429 w120 h30 , 1000-7 im ghoul
Gui, Font, S16 CWhite, Asinastra
Gui, Font, S14 CWhite, Asinastra
Gui, Font, S14 CWhite, Asinastra
Gui, Add, Text, x42 y309 w360 h30 , Script from discord.gg/S2tYVMNxNM
Gui, Add, Text, x42 y349 w330 h30 , ctrl+alt+q - script activation
Gui, Add, Text, x42 y269 w190 h30 , F9 - exit
Gui, Add, Text, x232 y269 w170 h30 , F10 - reload
; Generated using SmartGUI Creator 4.0
Gui, Show, x304 y107 h488 w451, New GUI Window
Return

^!z::SetTimer, Infinite, 50

Infinite:
    ControlSend,, ws, ahk_exe javaw.exe
Return

Activation:
    Gui, Submit, NoHide
return

!^q::
    Loop
    {
        ;main part
        ControlSend,, {%DestroyButton% down}, ahk_exe javaw.exe

        Loop, 3
        {
            CtrlSend("d", PressTimeAD, "ahk_exe javaw.exe")
            CtrlSend("w", 400, "ahk_exe javaw.exe")
            CtrlSend("a", 100, "ahk_exe javaw.exe")
            CtrlSend("w", 400, "ahk_exe javaw.exe")
            CtrlSend("a", PressTimeAD, "ahk_exe javaw.exe")
            sleep 100
            
            Loop, 12
            {
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("d", 100, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("d", PressTimeAD, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("a", 100, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("a", PressTimeAD, "ahk_exe javaw.exe")
                sleep 100
            }
        }

        Loop, 3
        {
            CtrlSend("a", PressTimeAD, "ahk_exe javaw.exe")
            CtrlSend("w", 400, "ahk_exe javaw.exe")
            CtrlSend("d", 100, "ahk_exe javaw.exe")
            CtrlSend("w", 400, "ahk_exe javaw.exe")
            CtrlSend("d", PressTimeAD, "ahk_exe javaw.exe")
            sleep 100

            Loop, 12
            {
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("a", 100, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("a", PressTimeAD, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("d", 100, "ahk_exe javaw.exe")
                CtrlSend("w", 400, "ahk_exe javaw.exe")
                CtrlSend("d", PressTimeAD, "ahk_exe javaw.exe")
                sleep 100
            }
        }
    }
return

CtrlSend(char,duration,wintitle) {
    sleep 100    
    ControlSend,, {%char% down}, % wintitle
    sleep duration
    ControlSend,, {%char% up}, % wintitle
}

F10::Reload

F9::
GuiClose:
GuiEscape:
ExitApp
return
Setting the gui font size multiple times in a row doesn't really do anything useful. Have fun hope this helps.

EmileWolf
Posts: 5
Joined: 13 Jan 2022, 09:42

Re: Help, ive tried several things but i cant find the right solution

Post by EmileWolf » 19 Jan 2022, 14:48

mikeyww wrote:
18 Jan 2022, 17:41
I'd go with this: viewtopic.php?p=438911#p438911. You can always add a hotkey to it if needed.
How can I add the hotkey? I want to run this on another script but I can't tell if the problem is the hotkey or that it isn't possible to run 2 scripts at once.
Thanks

EmileWolf
Posts: 5
Joined: 13 Jan 2022, 09:42

Re: Help, ive tried several things but i cant find the right solution

Post by EmileWolf » 19 Jan 2022, 15:48

Xtra wrote: I simplified your script with one function that cuts the script size in half.
You should be able to run a timer and the loops at the same time. If you have an issue with timing you can always run the timer part in its own script like mikey posted.
How can I add a hotkey to activate a script, I want to run the timer in another script but I think since they have the same hotkey it doesn't work.

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Help, ive tried several things but i cant find the right solution

Post by mikeyww » 19 Jan 2022, 19:24

I posted it at your other thread. I see no special need to have two scripts rather than one.

Post Reply

Return to “Gaming Help (v1)”