Sign in to follow this  
Followers 0
AlvinHu1991

Toggling a part of my script on and off

8 posts in this topic

#1 ·  Posted (edited)

Hello, I currently have a script that shows alerts on a tooltip for me.

But I want to be able to toggle certain scripts on and off by using HotKeySet.

Or if there's a way to rewrite into the running script without closing the script.

Here's my basic example scripts:

Script #1

If PixelGetColor(43, 834) = 0x4D3924 Then
ToolTip("Someone just messaged you.", @DesktopWidth / 2, 10, "", 1, 2)
Do
Sleep(100)
Until PixelGetColor(43, 834) = 0xE6CD94
Else
EndIf

Script #2

If Not PixelGetColor(883, 834) = 0x0A0503 Then
ToolTip("An attachment has arrived.", @DesktopWidth / 2, 10, "", 1, 2)
Do
Sleep(100)
Until PixelGetColor(883, 834) = 0x0A0503
Else
EndIf

Edit:

Basically I want to maintain several functions active.(With an option to toggle them on or off)

But with HotKeySet it will only allow one function active at a time.

If anyone can direct me to the direction or if its not possible, thank you!

Edited by AlvinHu1991

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Using HotKeySet you can do something like this:

HotKeySet("{F1}", "firstFunc")
HotKeySet("{F2}", "secondFunc")


While 1
    ; run indefinitely
WEnd


Func firstFunc()

    If PixelGetColor(43, 834) = 0x4D3924 Then
        ToolTip("Someone just messaged you.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
            Sleep(100)
        Until PixelGetColor(43, 834) = 0xE6CD94
    EndIf
    
EndFunc   ;==>firstFunc


Func secondFunc()

    If Not PixelGetColor(883, 834) = 0x0A0503 Then
        ToolTip("An attachment has arrived.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
            Sleep(100)
        Until PixelGetColor(883, 834) = 0x0A0503
    EndIf
    
EndFunc   ;==>secondFunc

EDIT: Hopefully this is what you mean, I think I'm a little confused on what you completely wanted. :)

EDIT: If you wanted these running in one loop, then when hitting the hotkey take out one, then you would just have 3 functions, 1 full with both script 1 & 2 (so you can toggle back to regular functionality), 1 with just script 1, and another with just script 2. :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Using HotKeySet you can do something like this:

HotKeySet("{F1}", "firstFunc")
HotKeySet("{F2}", "secondFunc")


While 1
    ; run indefinitely
WEnd


Func firstFunc()

    If PixelGetColor(43, 834) = 0x4D3924 Then
        ToolTip("Someone just messaged you.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
            Sleep(100)
        Until PixelGetColor(43, 834) = 0xE6CD94
    EndIf
    
EndFunc   ;==>firstFunc


Func secondFunc()

    If Not PixelGetColor(883, 834) = 0x0A0503 Then
        ToolTip("An attachment has arrived.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
            Sleep(100)
        Until PixelGetColor(883, 834) = 0x0A0503
    EndIf
    
EndFunc   ;==>secondFunc

EDIT: Hopefully this is what you mean, I think I'm a little confused on what you completely wanted. :)

EDIT: If you wanted these running in one loop, then when hitting the hotkey take out one, then you would just have 3 functions, 1 full with both script 1 & 2 (so you can toggle back to regular functionality), 1 with just script 1, and another with just script 2. :)

The problem with HotKeySet is it only allows one function to be activate at a time

So lets say when I press F1 then Press F2, F1 will be canceled out and F2 will be the only script running.

But I want them both to be on or off when I toggle them.

If toggling with HotKeySet is possible or not?

Or if there's a similar way of writing it and if you can show me any example or lead me to the function im looking for. Thanks

Edited by AlvinHu1991

Share this post


Link to post
Share on other sites

Which program do you try to automate? If the program offers a COM interface then you could try to automate this events.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The problem with HotKeySet is it only allows one function to be activate at a time

So lets say when I press F1 then Press F2, F1 will be canceled out and F2 will be the only script running.

But I want them both to be on or off when I toggle them.

If toggling with HotKeySet is possible or not?

Or if there's a similar way of writing it and if you can show me any example or lead me to the function im looking for. Thanks

HotKeySet("{F1}", "firstFunc")
HotKeySet("{F2}", "secondFunc")

Local $hDLL = DllOpen('User32.dll')

While 1
    ; run indefinitely
WEnd

Func firstFunc()
    Do
        If PixelGetColor(43, 834) = 0x4D3924 Then
        ToolTip("Someone just messaged you.", @DesktopWidth / 2, 10, "", 1, 2)
            Do
              Sleep(100)
            Until PixelGetColor(43, 834) = 0xE6CD94
        ElseIf Not PixelGetColor(883, 834) = 0x0A0503 Then
            ToolTip("An attachment has arrived.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
                    Sleep(100)
        Until PixelGetColor(883, 834) = 0x0A0503
    EndIf
    Until _IsPressed("71", $hDLL)
EndFunc   ;==>firstFunc

Func secondFunc()
    Do
    Until _IsPressed("70", $hDLL)
EndFunc   ;==>secondFunc

Maybe like this?

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Add two variables that are toggled whenever you press the designated hotkeys. Then check the variable in your main loop to determine if you should perform each specific section of code.

Share this post


Link to post
Share on other sites

Add two variables that are toggled whenever you press the designated hotkeys. Then check the variable in your main loop to determine if you should perform each specific section of code.

Thanks, It actually worked better than I thought!

 

HotKeySet("{F1}", "firstFunc")
HotKeySet("{F2}", "secondFunc")

Local $hDLL = DllOpen('User32.dll')

While 1
    ; run indefinitely
WEnd

Func firstFunc()
    Do
        If PixelGetColor(43, 834) = 0x4D3924 Then
        ToolTip("Someone just messaged you.", @DesktopWidth / 2, 10, "", 1, 2)
            Do
              Sleep(100)
            Until PixelGetColor(43, 834) = 0xE6CD94
        ElseIf Not PixelGetColor(883, 834) = 0x0A0503 Then
            ToolTip("An attachment has arrived.", @DesktopWidth / 2, 10, "", 1, 2)
        Do
                    Sleep(100)
        Until PixelGetColor(883, 834) = 0x0A0503
    EndIf
    Until _IsPressed("71", $hDLL)
EndFunc   ;==>firstFunc

Func secondFunc()
    Do
    Until _IsPressed("70", $hDLL)
EndFunc   ;==>secondFunc

Maybe like this?

Thanks for all your help!

1 person likes this

Share this post


Link to post
Share on other sites

My pleasure ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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