Jump to content

Need advice to minimized to tray


Recommended Posts

I'm new to AutoIT. Recently I try to make a simple script. How can I make make script minimized to tray instead of taskbar? Also everytime I pressed stop, my RUN and QUIT button wont work anymore. Pls help me...

Sample of my script:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Simple AutoAction", 324, 307, 231, 130)
$Label1 = GUICtrlCreateLabel("AutoScript for hunting WhiteTiger and Dragons [Assasin]", 24, 16, 270, 17)
$BStart = GUICtrlCreateButton("Start [F11]", 24, 40, 75, 25, 0)
$BStop = GUICtrlCreateButton("Stop [Alt-F11]", 120, 40, 75, 25, 0)
$BExit = GUICtrlCreateButton("Exit [Ctrl-F11]", 216, 40, 75, 25, 0)
$Group1 = GUICtrlCreateGroup("Controls", 8, 0, 305, 89)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Notes", 8, 96, 225, 201)
$Label2 = GUICtrlCreateLabel("Please set your shortcut to these settings:", 24, 120, 200, 17)
$Label3 = GUICtrlCreateLabel("F1 = Poison Smear", 40, 144, 93, 17)
$Label4 = GUICtrlCreateLabel("F2 = General Attack", 40, 168, 99, 17)
$Label5 = GUICtrlCreateLabel("F3 = Sit", 40, 192, 40, 17)
$Label6 = GUICtrlCreateLabel("F4 = Shadow Kill", 40, 216, 83, 17)
$Label7 = GUICtrlCreateLabel("F5 = Shadowless Tooth", 40, 240, 116, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Bye()
        Case $BExit
            Bye()
        Case $BStart
            Main()
        Case $BStop
            SStop()
    EndSwitch
WEnd

HotKeySet("{F11}", "Main")
HotKeySet("!{F11}", "SStop")
HotKeySet("^{F11}", "Bye")

Func Main()

    WinWait("Water Margin Online", "")
    If Not WinActive("Water Margin Online", "") Then WinActivate("Water Margin Online", "")
    WinWaitActive("Water Margin Online", "")

    $handle = ControlGetHandle("Water Margin Online", "", "")
    While 1
        ;Poison Smear
        ControlSend($handle, "", "", "{F1}")
        Sleep(4500) ; Delay
        ;General Atk
        ControlSend($handle, "", "", "{F2}")
        Sleep(1500) ; Delay
        ;Skill ShadowKill
        ControlSend($handle, "", "", "{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle, "", "", "{F5}")
        Sleep(4000) ; Delay
        ; General Atk
        ControlSend($handle, "", "", "{F2}")
        Sleep(21000) ; Delay
        ;Skill ShadowKill
        ControlSend($handle, "", "", "{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle, "", "", "{F5}")
        Sleep(4000) ; Delay
        ; General Atk
        ControlSend($handle, "", "", "{F2}")
        Sleep(21000) ; Delay
        ;Skill ShadowKill
        ControlSend($handle, "", "", "{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle, "", "", "{F5}")
        Sleep(4000) ; Delay
        ; Sit
        ControlSend($handle, "", "", "{F3}")
        Sleep(1000)
        ; Sit
        ControlSend($handle, "", "", "{F3}")
        Sleep(50000) ; Delay
    WEnd
EndFunc   ;==>Main

;;Need help in this part, after stop, the run and quit button not working anymore >.<
Func SStop()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>SStop

Func Bye()
    Exit
EndFunc   ;==>Bye

Pls help and guide me, thank you :)

Edited by CyberDrag0n
Link to comment
Share on other sites

I'm new to AutoIT. Recently I try to make a simple script. How can I make make script minimized to tray instead of taskbar? Also everytime I pressed stop, my RUN and QUIT button wont work anymore. Pls help me...

Sample of my script:

Pls help and guide me, thank you :)

You want to read up on using GuiOnEvent mode instead of Gui Message. Clicking on your GUI buttons in the above script only generates a message that will be ignored if not read with "$nMsg = GuiGetMsg()". Since you pause function is trapped in a loop, it never reads the message, so your script doesn't know the button was pushed.

An alternative is set events functions for the GUI and the button controls, then the function gets run when the button is pushed. There are good examples in the Help File.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok, thanks for the advice.. I've modified the script. Everytime I press the stop button, my exit and start button will stop functioning. Also the script seems slow... Can someone pls help and correct the script and optimized for me? Thanks..

#include <GUIConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Opt("TrayIconHide", 0)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
TraySetState()

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AutoKiller", 331, 307, 193, 115)
$MyTittle = GUICtrlCreateLabel("Beast AutoKiller", 16, 8, 301, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$MCommands = GUICtrlCreateGroup("Main Commands", 16, 40, 297, 89)
$BRun = GUICtrlCreateButton("RUN [F11]", 24, 72, 83, 25, 0)
$BStop = GUICtrlCreateButton("STOP [Alt-F11]", 120, 72, 83, 25, 0)
$BExit = GUICtrlCreateButton("Exit [Esc]", 216, 72, 83, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Notice = GUICtrlCreateGroup("Notice", 16, 152, 297, 137)
$N1 = GUICtrlCreateLabel("Pls. make sure that you set your shortcut to followings:", 24, 176, 259, 17)
$N2 = GUICtrlCreateLabel("F1 = Poison Smear", 40, 208, 93, 17)
$N3 = GUICtrlCreateLabel("F2 = General Atk", 40, 232, 84, 17)
$N4 = GUICtrlCreateLabel("F3 = Sit", 40, 256, 40, 17)
$N5 = GUICtrlCreateLabel("F4 = Shadow Kill", 160, 208, 83, 17)
$N6 = GUICtrlCreateLabel("F5 = Shadowless Tooth", 160, 232, 116, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "SBye")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SMin")
GUICtrlSetOnEvent($BRun, "SMain")
GUICtrlSetOnEvent($BStop, "SStop")
GUICtrlSetOnEvent($BExit, "SBye")

HotKeySet("{F11}", "SMain")
HotKeySet("!{F11}", "SStop")
HotKeySet("{ESC}", "SBye")

$handle = ControlGetHandle("Water Margin Online", "", "")

While 1
    Sleep(1000)
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    Opt("TrayIconHide", 1)
EndFunc

Func SMin()
    GuiSetState(@SW_HIDE)
    Opt("TrayIconHide", 0)
    TrayTip("", "Click to restore.", 5)
EndFunc

Func SBye()
    Exit
EndFunc

Func SStop()
    While 1
        Sleep(1000)
    WEnd
EndFunc

Func SMain()

    WinWait("Water Margin Online","")
    If Not WinActive("Water Margin Online","") Then WinActivate("Water Margin Online","")
    WinWaitActive("Water Margin Online","")

    While 1
        ;Poison Smear
        ControlSend($handle,"", "","{F1}")
        Sleep(5000) ; Delay
        ;General Atk
        ControlSend($handle,"", "","{F2}")
        Sleep(1000) ; Delay
        ;Skill ShadowKill
        ControlSend($handle,"", "","{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle,"", "","{F5}")
        Sleep(4000) ; Delay
        ; General Atk
        ControlSend($handle,"", "","{F2}")
        Sleep(21000) ; Delay
        ;Skill ShadowKill
        ControlSend($handle,"", "","{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle,"", "","{F5}")
        Sleep(4000) ; Delay
        ; General Atk
        ControlSend($handle,"", "","{F2}")
        Sleep(21000) ; Delay
        ;Skill ShadowKill
        ControlSend($handle,"", "","{F4}")
        Sleep(4000) ; Delay
        ;Skill ShadowlessTooth
        ControlSend($handle,"", "","{F5}")
        Sleep(4000) ; Delay
        ; Sit
        ControlSend($handle,"", "","{F3}")
        Sleep(1000)
        ; Sit
        ControlSend($handle,"", "","{F3}")
        Sleep(50000) ; Delay
    WEnd
EndFunc
Edited by CyberDrag0n
Link to comment
Share on other sites

Ok, thanks for the advice.. I've modified the script. Everytime I press the stop button, my exit and start button will stop functioning. Also the script seems slow... Can someone pls help and correct the script and optimized for me? Thanks..

Tighten up these sleeps:

While 1
    Sleep(20)
WEndoÝ÷ Ù«­¢+ÙÕ¹MMѽÀ ¤(]¡¥±Ä(M±À ÈÀ¤(]¹)¹Õ¹

Other than that, I don't see why it shouldn't respond to the start and exit buttons after hitting stop.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Tighten up these sleeps:

While 1
    Sleep(20)
WEndoÝ÷ Ù«­¢+ÙÕ¹MMѽÀ ¤(]¡¥±Ä(M±À ÈÀ¤(]¹)¹Õ¹

Other than that, I don't see why it shouldn't respond to the start and exit buttons after hitting stop.

:)

I've followed your instruction and modified the delay to '20' but still the same. Try run the script. When then gui appear, try click the STOP button first then only the EXIT button... The EXIT button wont work after I clicked the STOP button.. I'm so confuse.. Pls. advice, thanks :D Edited by CyberDrag0n
Link to comment
Share on other sites

I've followed your instruction and modified the delay to '20' but still the same. Try run the script. When then gui appear, try click the STOP button first then only the EXIT button... The EXIT button wont work after I clicked the STOP button.. I'm so confuse.. Pls. advice, thanks :)

The Tray stuff is irrelevant to the problem, and I don't have the app you are running.

Here's a stripped down version that works and shows a better way to handle conditional execution:

#include <GUIConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)

Global $Run = 0, $n = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AutoKiller", 331, 307, 193, 115)
$MyTittle = GUICtrlCreateLabel("Beast AutoKiller", 16, 8, 301, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$MCommands = GUICtrlCreateGroup("Main Commands", 16, 40, 297, 89)
$BRun = GUICtrlCreateButton("RUN [F11]", 24, 72, 83, 25, 0)
$BStop = GUICtrlCreateButton("STOP [Alt-F11]", 120, 72, 83, 25, 0)
$BExit = GUICtrlCreateButton("Exit [Esc]", 216, 72, 83, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Notice = GUICtrlCreateGroup("Notice", 16, 152, 297, 137)
$N1 = GUICtrlCreateLabel("Pls. make sure that you set your shortcut to followings:", 24, 176, 259, 17)
$N2 = GUICtrlCreateLabel("F1 = Poison Smear", 40, 208, 93, 17)
$N3 = GUICtrlCreateLabel("F2 = General Atk", 40, 232, 84, 17)
$N4 = GUICtrlCreateLabel("F3 = Sit", 40, 256, 84, 17)
$N5 = GUICtrlCreateLabel("F4 = Shadow Kill", 160, 208, 83, 17)
$N6 = GUICtrlCreateLabel("F5 = Shadowless Tooth", 160, 232, 116, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "SBye")
GUICtrlSetOnEvent($BRun, "SRun")
GUICtrlSetOnEvent($BStop, "SStop")
GUICtrlSetOnEvent($BExit, "SBye")

HotKeySet("{F11}", "SMain")
HotKeySet("!{F11}", "SStop")
HotKeySet("{ESC}", "SBye")

While 1
    If $Run Then SMain()
    Sleep(1000)
WEnd

Func SRun()
    $Run = 1
EndFunc   ;==>SRun

Func SStop()
    $Run = 0
EndFunc   ;==>SStop

Func SBye()
    Exit
EndFunc   ;==>SBye

Func SMain()
    $n += 1
    SplashTextOn("AutoKiller", "$n = " & $n, 200, 100, 50, 50, 16)
EndFunc   ;==>SMain

Hope that helps!

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...