Jump to content

Recommended Posts

  • Moderators
Posted

Hi all,

For reasons that are too complicated to explain in a short post I wanted to create a function which could be called by a HotKey (which ignores any parameters) and also called programmatically from within the script with various parameters. After much experimentation I came up with the following syntax and logic:

Global $bFlag_1 = False, $bFlag_2 = False

HotKeySet("^r", "_Test")

HotKeySet("{ESC}", "_Exit")

; Default param so no action taken
_Test()

; Use param to set Flag_1 to True
_Test(1)

; And back to False
_Test(0)

; Now play with the HotKey to change Flag_2

While 1
    Sleep(10)
WEnd

Func _Test($vParam = 9999)

    #forceref $vParam ; Prevents Au3Check warning

    Eval("vParam")
    If Not @error Then
        ; Fired programatically so use parameter to set/clear Flag_1
        Switch Eval("vParam")
            Case 9999
                ; Do nothing
            Case 0
                $bFlag_1 = False
            Case 1
                $bFlag_1 = True
        EndSwitch
    Else
        ; Not fired programatically so parameter ignored and set/clear Flag_2
        $bFlag_2 = Not $bFlag_2
    EndIf

    ConsoleWrite($bFlag_1 & " - " & $bFlag_2 & @CRLF)

EndFunc

Func _Exit()
    Exit
EndFunc

Does anyone have a better way of doing this?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Developers
Posted

No sure it is simpler but a little different approach:

Func _Test($vParam = 9999)

    #forceref $vParam ; Prevents Au3Check warning
    If Not @NumParams Then
        If Eval("vParam") <> 9999 Then
            ; Not fired programatically so parameter ignored and set/clear Flag_2
            $bFlag_2 = Not $bFlag_2
        EndIf
    Else
        ; Fired programatically so use parameter to set/clear Flag_1
        $bFlag_1 = ($vParam <> 0)
    EndIf

    ConsoleWrite($bFlag_1 & " - " & $bFlag_2 & "  @NumParams=" & @NumParams & @CRLF)

EndFunc   ;==>_Test

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Moderators
Posted

Jos,

I like the use of @NumParams rather then using Eval twice - thanks for the tip.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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