Moderators Melba23 Posted April 21, 2018 Moderators Share Posted April 21, 2018 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: expandcollapse popupGlobal $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 Earthshine 1 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Developers Jos Posted April 21, 2018 Developers Share Posted April 21, 2018 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 Earthshine 1 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 21, 2018 Author Moderators Share Posted April 21, 2018 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now