Jump to content

Toggling a part of my script on and off


Go to solution Solved by Danp2,

Recommended Posts

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
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

  Reveal hidden contents

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

 

Posted (edited)
  On 11/3/2014 at 3:29 PM, MikahS said:

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
Posted

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:

  Reveal hidden contents

 

Posted (edited)
  On 11/3/2014 at 3:53 PM, AlvinHu1991 said:

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

  Reveal hidden contents

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

 

Posted
  On 11/3/2014 at 4:16 PM, Danp2 said:

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!

 

  On 11/3/2014 at 4:09 PM, MikahS said:
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!

Posted

My pleasure ;)

Snips & Scripts

  Reveal hidden contents

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

 

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
  • Recently Browsing   0 members

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