Sign in to follow this  
Followers 0
Christopher Blue

Starting a AU3 script from within an AU3 script.

16 posts in this topic

I have tried simply using the "Run" function but it fails. I also tried using @ComSpec but it isn't working either. What are my options besides compiling my scripts into .exes?

Share this post


Link to post
Share on other sites



If you #include a script into your main script the non-functioned (not put into functions) code will execute at the time of the call. Example:

main.AU3

If Not @compiled then
   #include "include.au3"
endif

include.au3

msgbox(0,"", "This script it not compiled!")

It is a simple example but I believe it works.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

That is an interesting solution Matt and I can see how it will work. However, some of my scripts have duplicate function names which causes problems. While I can rewrite the names, I am still interesting in how I could simply run each script as its own separate process.

Share this post


Link to post
Share on other sites

That is the only solution that I have seen without compiling each script seperatly, I too would like to see another way to solve this problem.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

My hotkeys only work with the first included script! What am I doing wrong?

Share this post


Link to post
Share on other sites

Without seeing your code I cannot diagnose your problem.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

CSS Multi-Launch.au3:

#include "Window Movement and Resize.au3"
#include "Burst Fire.au3"
#include "Throw Grenade.au3"

Burst Fire.au3:

$keywait = 150

Opt("WinTitleMatchMode", 3)
Opt("SendKeyDelay", 0)

$window_name = "Counter-Strike Source"
$hotkey1 = "01";Left mouse button
$hotkey2 = "{TAB}"
$burst_active = 0
$burstfireon = 0
$rounds = 0
$rest = 5

HotKeySet($hotkey2, "ToggleBurstFire")

While (1)
    If ((_IsPressed($hotkey1) = 1) AND WinActive($window_name) AND $burstfireon) Then
        FireBurst()
    EndIf
    Sleep ($rest)
WEnd

Func FireBurst()
    If ($burstfireon = 3) Then
        $rounds = 3
        $keywait = 150
    Else
        $rounds = 10
        $keywait = 250
    EndIf

    For $i = 0 To ($rounds - 2) Step 1
        Sleep($keywait)
        Send("{LCTRL}")
    Next

    If (WinActive($window_name)) Then
        Send("{F11}")
        Sleep($keywait)
    EndIf
EndFunc

Func ToggleBurstFire()
    Select
            Case $burstfireon = 0
            $burstfireon = 3
           Case $burstfireon = 3
            $burstfireon = 10
            Case Else
            $burstfireon = 0
    EndSelect

    HotKeySet($hotkey2)
    Send($hotkey2)
    HotKeySet($hotkey2, "ToggleBurstFire")
EndFunc
    






; ezzetabi's _IsPressed function
Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
  
  Local $aR, $bRv;$hexKey
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
;If $aR[0] = -32767 Then
  If $aR[0] <> 0 Then
     $bRv = 1
  Else
     $bRv = 0
  EndIf
  
  Return $bRv
EndFunc;==>_IsPressed

Throw Grenade.au3:

Opt("WinTitleMatchMode", 3)

$window_name = "Counter-Strike Source"
$throw_hotkey = "{F1}"
$throw_active = 0
$rest = 10

HotKeySet($throw_hotkey, "Toss")

while (1)
    Sleep(2147483647)
WEnd

Func Toss()
    If (WinActive($window_name) AND ($throw_active == 0)) Then
        $throw_active = 1
        Send("4")
        Sleep($rest)
        Send("{LCTRL}")
        Sleep(700)
        Send("{LCTRL}")
        $throw_active = 0
    Else
        HotKeySet($throw_hotkey)
        Send($throw_hotkey)
        HotKeySet($throw_hotkey, "Toss")
    EndIf
EndFunc

Window Movement and Resize.au3:

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 3)

Global $GWL_STYLE = -16
$window_name = "Counter-Strike Source"
$hidden = 0
$window_hotkey = "!q"

HotKeySet($window_hotkey, "ToggleWindowHide")

; Move the Window into postion
WinMove($window_name, "", 0, 0, 1024, 768)
;WinMove($window_name, "", -3, -29)

RemoveWindowBorders()
; Wait for hotkey input
while (1)
    Sleep (2147483647)
WEnd

; Hides/Unhides window
Func ToggleWindowHide()
    If ($hidden) Then
        WinMove($window_name, "", 0, 0)
    Else    
        WinMove($window_name, "", -5000, -5000)
    EndIf
    $hidden = NOT $hidden
EndFunc

;Remove the window borders
Func RemoveWindowBorders()
    $hWnd = WinGetHandle($window_name)

    $OldStyle = DLLCall( "user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE )
    If @error Then Exit
    $OldStyle = $OldStyle[0]

    $NewStyle = BitAND($OldStyle,BitNOT($WS_DLGFRAME) )
    $NewStyle = BitAND($NewStyle,BitNOT($WS_THICKFRAME) )
    $NewStyle = BitAND($NewStyle,BitNOT($WS_BORDER) )

    DLLCall( "user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", $NewStyle )
EndFunc
Edited by Christopher Blue

Share this post


Link to post
Share on other sites

From what I can tell it never makes it to the second script. I can't test it because I don't have counter-strike, but logically reading through your code... it gets stuck on the inifinite while loop in the first script included.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

I could remove the loops and put one in the multi-call script...but that would mean I'd be tailoring the separate scripts to fulfill the needs of the caller...which isn't what I wish to do. I think I shall try to find a different method way of starting all of my scripts at once.

Share this post


Link to post
Share on other sites

Larry, what is the difference between using a long sleep and infinitely looping a short sleep?

Share this post


Link to post
Share on other sites

include will not work for independently whole scripts. You will need to run them... compile them to run them all at once. Also, I noticed the long Sleep()... no good... make it short like 100

Lar.

<{POST_SNAPBACK}>

^^^^ This is god's word on the topic ^^^^

Share this post


Link to post
Share on other sites

Larry, what is the difference between using a long sleep and infinitely looping a short sleep?

<{POST_SNAPBACK}>

If you have a long sleep, your script will not pick up the hotkeys you are looking for. This actually holds the script from any input. I think that is right, Larry can verify.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

But my hotkeys have worked before with the long sleeps. I just sleep to keep the script from exiting for my hotkey-only scripts.

Share this post


Link to post
Share on other sites

Running multiple AutoIt scripts from AutoIt requires that I compile the scripts which complicates the coding process since I have to remember to compile after each new change.

Using a simple batch file can do the job but the popup command window it makes is annoying.

However, I have been able to create a solution using WSH that fits my needs:

CSS Multi-Launch.vbs:

set Wshshell= WScript.createobject("wscript.shell")
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Burst Fire.au3" + chr(34))
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Throw Grenade.au3" + chr(34))
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Window Movement and Resize.au3" + chr(34))

This will work until AutoIt3 supports running non .exe programs.

Share this post


Link to post
Share on other sites

Sounds good Larry. I will check those out, thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0