Jump to content
Sign in to follow this  
Fr33b0w

Tray Icon Pause/Unpause

Recommended Posts

Fr33b0w

I am using one script often which I am pausing a lot. I know its not a big deal to right click it then unpause but when You do that EVERY DAY more then a hundred times it become anoying... I was looking for solution but I couldnt get any in hours of searching...

I did try

AutoItSetOption ( "option" [, param] )

but I couldnt get it to work...

Is there a simple solution for this:

On left click both PAUSE and UNPAUSE script (script pauses without opening a menu)

hmmmm i will try to setup a hotkey for that but I am wondering is there a way to set it up with left mouse click...

Share this post


Link to post
Share on other sites
Melba23

Fr33b0w,

I think this should do what you want: :mellow:

#include <GUIConstantsEx.au3>
#include <Constants.au3>

$fPaused = "False"

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

; Create tray menu
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Set function for left click on icon
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")

; Tray context menu only opened by right click
TraySetClick(16)

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Paused = ", 10, 10, 50, 20)
$hLabel = GUICtrlCreateLabel($fPaused, 60, 10, 100, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $fPaused <> GUICtrlRead($hLabel) Then
        GUICtrlSetData($hLabel, $fPaused)
    EndIf

WEnd

Func On_Click()

    Switch $fPaused
        Case "False"
            $fPaused = "True"
        Case Else
            $fPaused = "False"
    EndSwitch

EndFunc

Func On_Exit()
    Exit
EndFunc

All clear? :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Fr33b0w

Fr33b0w,

I think this should do what you want: :mellow:

All clear? :P

M23

After more then one hour looking at your example almost everything is clear! :party: Thanks! And I have one more little question:

Is it possible when its paused to use that red cross over the icon (default pause)? I did set it with this tooltip but it just dont look good (script works and everything but can I set an icon indicator as red cross...)

Script already uses two different icons for diff modes... And i have third pause mode now... can it be done with red cross over the icon that has been used? MANY THANKS!

Func On_Click()
    Switch $fPaused
        Case "False"
        false1 ()
        Case Else
        true1 ()
    EndSwitch
EndFunc

Func On_Exit()
    Exit
EndFunc


Func false1()
ToolTip('------------------------------ NOW PLAY SCRIPT PAUSED ------------------------------',0,0)
TraySetPauseIcon()
$fPaused = "True"
EndFunc

Func true1()
$fPaused = "False"
ToolTip('',0,0)
TraySetPauseIcon()
EndFunc

PS: Or if there is a way to save somehow condition of the icon that is presented in tray, replace it with pause icon and when tray icon is clicked again (unpaused) then to restore icon that was in the tray (i have two different ones in a tray...)

Edited by Fr33b0w

Share this post


Link to post
Share on other sites
Melba23

Fr33b0w,

If you compile this, yuo get the red "X" icon when the script is paused and the normal icon when it is not:

#include <GUIConstantsEx.au3>
#include <Constants.au3>

$fPaused = "False"

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

; Create tray menu
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Set function for left click on icon
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")

; Tray context menu only opened by right click
TraySetClick(16)

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Paused = ", 10, 10, 50, 20)
$hLabel = GUICtrlCreateLabel($fPaused, 60, 10, 100, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $fPaused <> GUICtrlRead($hLabel) Then
        GUICtrlSetData($hLabel, $fPaused)
    EndIf

WEnd

Func On_Click()

    Switch $fPaused
        Case "False"
            $fPaused = "True"
            TraySetIcon(@ScriptFullPath, -3) ; use red X tray icon
        Case Else
            $fPaused = "False"
            TraySetIcon(@ScriptFullPath, 0) ; use default icon
    EndSwitch

EndFunc

Func On_Exit()
    Exit
EndFunc

Is that what you wanted? :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Fr33b0w

Dont know what I did wrong it wont pause anymore... just to check everything once again... I have hotkeys inside? Thay also pause right?

Share this post


Link to post
Share on other sites
Melba23

Fr33b0w,

If you do not post the code you are having problems with, how am I (or anyone else) supposed to help? :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Fr33b0w

Fr33b0w,

If you do not post the code you are having problems with, how am I (or anyone else) supposed to help? :mellow:

M23

I didnt wanted to confuse You... but I really cant find whats wrong now...

;---------------- working version v0.008 ----------------
; - send np on numpad0
; - duplicates not possible

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=..\Desktop\Winamp Tracklister.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Winamp lister
;Lists songs that are played in winamp

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <Winamp_Library.au3>
$fPaused = "False"
Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

; Create tray menu
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Set function for left click on icon
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")

; Tray context menu only opened by right click
TraySetClick(16)



HotKeySet("{PAUSE}", "automated")
HotKeySet("{NUMPAD0}", "sendnp")
TraySetIcon(@ScriptDir & "\npspam.ico",-1)
$count=IniRead("npspam.ini", "Counter", "counter", "0")
$hFile=@ScriptDir&'\Tracklist.txt'
$icon=1
While 1
Sleep(10000);Update interval
Wend

Func sendnp()

$Track=_Winamp_GetCurrentTrackTitle()
    If stringinstr(FileRead($hFile),$Track)=0 then;No dupes plox
        Filewriteline($hFile,@MDAY&'/'&@MON&'/'&@YEAR&' Time: ' &@HOUR & ':' & @MIN & ":" & @SEC&' - '&$Track&@CRLF)
        FileClose($hFile)
        sendit()
        Endif
    EndFunc


Func sendit()
WinActivate ("Test APP")
    WinWaitActive("Test APP")
Send("[auto_no: " & $count & "] " & "^!z")
$count=$count+1
IniWrite("npspam.ini", "Counter", "counter", $count)
EndFunc


Func automated()
    TraySetIcon(@ScriptDir & "\npspama.ico",-1)
    $icon=2
    $paused = NOT $paused
    While $paused
        sleep(100)
        ToolTip('------------------------------ NOW PLAY SCRIPT AUTOMATED ------------------------------',0,0)
        $Track=_Winamp_GetCurrentTrackTitle()
        If stringinstr(FileRead($hFile),$Track)=0 then;No dupes plox
        Filewriteline($hFile,@MDAY&'/'&@MON&'/'&@YEAR&' Time: ' &@HOUR & ':' & @MIN & ":" & @SEC&' - '&$Track&@CRLF)
        FileClose($hFile)
        sendit ()
        Endif
Sleep(3000);Update interval
WEnd
ToolTip('',0,0)
TraySetIcon(@ScriptDir & "\npspam.ico",-1)
$icon=1
EndFunc



Func On_Click()
    Switch $fPaused
        Case "False"
        $fPaused = "True"
        false1 ()
        Case Else
        true1 ()
        $fPaused = "False"
    EndSwitch
EndFunc

Func On_Exit()
    Exit
EndFunc


Func false1()
ToolTip('------------------------------ NOW PLAY SCRIPT PAUSED ------------------------------',0,0)
TraySetIcon(@ScriptDir & "\npspamp.ico",-1)
EndFunc

Func true1()
ToolTip('',0,0)
Select
Case $icon=1
TraySetIcon(@ScriptDir & "\npspam.ico",-1)
Case $icon=2
TraySetIcon(@ScriptDir & "\npspama.ico",-1)
EndSelect
EndFunc

part of the script is frm here:

Part of the code

Share this post


Link to post
Share on other sites
Melba23

Fr33b0w,

I have removed the WinAmp related code because I do not have the app, but it is easy to put back in. :P

What you have here is a script that stays inactive until you press the "Pause" button. At this point the script activates and changes icon to show this. Now the script is activated, pressing the "Pause" button or clicking the tray icon toggles the script between active and paused states - changing the icon and tooltip to reflect this.

#include <GUIConstantsEx.au3>
#include <Constants.au3>

Global $fRunning = False, $fAutomated = False

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

; Create tray menu
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Set function for left click on icon
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")

; Tray context menu only opened by right click
TraySetClick(16)

HotKeySet("{PAUSE}", "automated")
;HotKeySet("{NUMPAD0}", "sendnp")
$count = IniRead("npspam.ini", "Counter", "counter", "0")
$hFile = @ScriptDir & '\Tracklist.txt'


While 1

    ; Has the script been activatd by an initial press on the Pause key?
    If $fAutomated Then
        ; Do your WinAmp stuff here
    EndIf

    Sleep(10000) ; Update interval

WEnd

Func automated()
    ; The script is now activated
    $fAutomated = True
    ToolTip('------------------------------ NOW PLAY SCRIPT AUTOMATED ------------------------------', 0, 0)
    Sleep(2000) ; So automated tooltip shows!
    ; From now on the Pause button acts as if we clicked on the tray icon
    On_Click()
EndFunc   ;==>automated

Func On_Click()
    ; Has the script been activated by a press on the Pause button
    If $fAutomated Then
        ; If so then switch the state
        $fRunning = Not $fRunning
        ; Now set the correct tooltip and icon
        Switch $fRunning
            Case True
                ToolTip('------------------------------ NOW PLAY SCRIPT RUNNING ------------------------------', 0, 0)
                TraySetIcon(@ScriptDir & "\Automated.ico")
            Case Else
                ToolTip('------------------------------ NOW PLAY SCRIPT PAUSED ------------------------------', 0, 0)
                TraySetIcon(@ScriptDir & "\Paused.ico")

        EndSwitch
    EndIf
EndFunc   ;==>On_Click

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

The icons I used are here:

I hope this is what you wanted - ask again if not. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Fr33b0w

I hope this is what you wanted - ask again if not. :mellow:

M23

MANY MANY THANKS! I will try it when i get back home! I know it will work! Where do You find time for all that? Saved the day and many more...

Share this post


Link to post
Share on other sites
VII

Hello, new to AutoIt. Hopefully someone can help me with this. When I leave my client window, and move to another program, the Autoit pauses, but when I comeback it won't unpause. It appears to be unpaused, but the original client that I'm using the AutoIt for, it won't unpause there. But I can tell it is still active when I go to type in other areas.

HotKeySet("{v}","jump")
HotKeySet("{PAUSE}", "unbind")

func jump() ; normal jump
    HotKeySet("{v}")
    Send("{0}")
    Sleep(1600)
    Send ("{w down}")
    Sleep(70)
    Send("{space}")
    Send("{w up}")
    HotKeySet("{v}", "jump")
    idle()
EndFunc

Func idle(); idle, do nothing
    while 1
        Sleep (1000)
    WEnd
EndFunc


Func unbind(); unbind keys
    HotKeySet("{v}")
    HotKeySet("{PAUSE}", "unbind")
    idle()
EndFunc

Func rebind() ; rebind keys
    HotKeySet("{v}", "jump")
    HotKeySet("{PAUSE}", "rebind")
    idle()
EndFunc


 idle()

Thanks, VII

Share this post


Link to post
Share on other sites
Fr33b0w

Hello, new to AutoIt. Hopefully someone can help me with this. When I leave my client window, and move to another program, the Autoit pauses, but when I comeback it won't unpause. It appears to be unpaused, but the original client that I'm using the AutoIt for, it won't unpause there. But I can tell it is still active when I go to type in other areas.

Thanks, VII

It would be better if you did made new topic... I think somebody would answer You... Mine problem was that if i pause script hotkeys would still work... So I guess I had to change those hotkeys to do nothing when in pause mode and to get them back when unpause. I made it happen with another active script and hotkey which would start again that script and a hotkey in main script to get out of the script. That way it all worked for me...

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.