Jump to content
Sign in to follow this  
Merchants

Run 2 functions at one time (tray stuff)

Recommended Posts

Merchants

if i run this script and don't press F9 then the tray stuff works fine but if i press F9 and wana try the tray stuff again it does not work

if i don't use tray stuff auto it wil set it as default if i do that then i can press F9 and do the tray stuff at the same time..

help?

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
Global $Pauze, $Exit, $tray = 0

$Pauze = TrayCreateItem("Pauze")
TrayCreateItem("")
$Exit = TrayCreateItem("Exit")

TraySetState()
HotKeySet("{F9}","Start")

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $pauze
            If $tray = 1 Then
                TrayItemSetState($pauze,$TRAY_UNCHECKED)
            Else
                TrayItemSetState($pauze,$TRAY_CHECKED)
                $tray = 0
            EndIf
        Case $msg = $Exit
            Exit
    EndSelect
WEnd

Func Start()
    Sleep(60000) ;60000 = 1 min
EndFunc

Share this post


Link to post
Share on other sites
FlyinRiz

if i run this script and don't press F9 then the tray stuff works fine but if i press F9 and wana try the tray stuff again it does not work

if i don't use tray stuff auto it wil set it as default if i do that then i can press F9 and do the tray stuff at the same time..

help?

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
Global $Pauze, $Exit, $tray = 0

$Pauze = TrayCreateItem("Pauze")
TrayCreateItem("")
$Exit = TrayCreateItem("Exit")

TraySetState()
HotKeySet("{F9}","Start")

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $pauze
            If $tray = 1 Then
                TrayItemSetState($pauze,$TRAY_UNCHECKED)
            Else
                TrayItemSetState($pauze,$TRAY_CHECKED)
                $tray = 0
            EndIf
        Case $msg = $Exit
            Exit
    EndSelect
WEnd

Func Start()
    Sleep(60000) ;60000 = 1 min
EndFunc

While the script is paused for 1 minute, it's ignoring all other items (including your entire While loop), so it will process the tray items just after that minute is up. What is the purpose of the Start function. There are other ways of doing this so that it doesn't block the rest of the script.

-Aaron

Share this post


Link to post
Share on other sites
Merchants

well is there a way to fix this ?

btw Func start() is not only sleep i just put it there to show you what i meen there comes more then only sleep

Share this post


Link to post
Share on other sites
Merchants

i have fond in a other post how to do it

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)
Global $Pauze, $Exit, $tray = 0

$pauze = TrayCreateItem("Pauze")
TrayItemSetOnEvent($pauze, "Pauze")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState()
HotKeySet("{F9}","Start")

While 1
    Sleep(10)
WEnd

Func Pauze()
    If $tray = 1 Then
        TrayItemSetState($pauze,$TRAY_UNCHECKED)
        $tray = 0
    Else
        TrayItemSetState($pauze,$TRAY_CHECKED)
        $tray = 1
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

Func Start()
    Sleep(60000) ;60000 = 1 min
EndFunc
Edited by Merchants

Share this post


Link to post
Share on other sites
Merchants

next problem some how if i start him up then i can select pauze

then it checked the tray pauze and if i press pauze again it runs the function start

but if i press pauze again it does not work (stuck) exit also

help?

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)
Global $Pauze, $tray = 0

$pauze = TrayCreateItem("Pauze")
TrayItemSetOnEvent($pauze, "Pauze")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState()
HotKeySet("{F9}","Start")

While 1
    Sleep(10)
WEnd

Func Pauze()
    If $tray = 1 Then
        TrayItemSetState($pauze,$TRAY_UNCHECKED)
        $tray = 0
        Start()
    Else
        TrayItemSetState($pauze,$TRAY_CHECKED)
        $tray = 1
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

Func Start()
    Sleep(60000) ;60000 = 1 min
EndFunc
Edited by Merchants

Share this post


Link to post
Share on other sites
FlyinRiz

got idees ?

If you posted the entire script it might help with this troubleshooting.

-Aaron

Share this post


Link to post
Share on other sites
Merchants

demo is better but this was already posted

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
Opt("TrayOnEventMode", 1)
Global $Pauze, $tray = 0

$pauze = TrayCreateItem("Pauze")
TrayItemSetOnEvent($pauze, "Pauze")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState()
HotKeySet("{F9}","Start")

While 1
    Sleep(10)
WEnd

Func Pauze()
    If $tray = 1 Then
        TrayItemSetState($pauze,$TRAY_UNCHECKED)
        $tray = 0
        Start()
    Else
        TrayItemSetState($pauze,$TRAY_CHECKED)
        $tray = 1
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

Func Start()
    Sleep(60000) ;60000 = 1 min
EndFunc
Edited by Merchants

Share this post


Link to post
Share on other sites
ShawnW

The problem is still your long and unaware start function. I say unaware because it does not check back with the state of the tray and also the tray starts a new instance of start every time weather or not any previous ones are finished.

You need to make a smarter start function, so that after it does anything important, it checks the $tray variable to see if it should continue. You do need to decide though if you want it to start over in a new instance of start when you uncheck pause.

If you want 1 instance of Start() and when paused it stops and when unpaused it picks up where it left off then do this...

If $tray = 0 means go and $tray = 1 means it is paused then just insert this line throughout the Start() function. The more often you check the more accurately you can pause.

While $tray
    Sleep(10)
Wend

This causes the start function to not continue what it is doing until the $tray variable toggles back to 0.

You also need a global variable to determine if start() is running something like Global $running = false

Then when instead of just calling Start() every time you uncheck pause, you can say...

If Not $running Then
    $running = True
    $running = Start()
EndIf
; Also at the end of Start(), Return False to set $running back to false.

This way if nothing is running a new Start() is called, but if it is already running, just paused, then it will just set $tray to 0 which lets the current Start() finish.

... Hope you followed that.

Anyway if you want to do it more like you have now, where a new Start() gets called every time you uncheck pause, and when you check pause again it just stops the exits the function and waits to restart it, then you can do the same thing I said about making the start function smater but use this line instead.

If $tray Then Return
Edited by ShawnW

Share this post


Link to post
Share on other sites
Merchants

can you make a simpel demo script that wil be very usefull to me and other users

and it goes faster

Edited by Merchants

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.