Jump to content
Melba23

Function with both HotKey and Program calls

Recommended Posts

Melba23

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

  • Like 1

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
Jos

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

  • Like 1

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

Share this post


Link to post
Share on other sites
Melba23

Jos,

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

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

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

×