Jump to content

Recommended Posts

Posted

Hi,

Does anyone know if there is a work around or alternatives to having a function with in a function.

Here is why:

I have created a gui application with menu items.

Every menu item envokes a function.(sends key strokes, etc.)

I need an abort hotkey so that if the user needs to cancel the function they started.

It is impossible to create a hotkey function within an existing function.

Any help is appreciated.

Radsam

Posted

do you really need that hotkey function in the other function? why not like this:?

Func Your_Other_Function ()
statements...
HotKeySet ("{ESC}", "MyExit")
EndFunc

Func MyExit ()
Exit
EndFunc

or put the first function on the bottom and the MyExit on top... is that what you want?

FootbaG
Posted

Unfortunately I had thought of this already but what happens is that the 1st function will play out THEN intiate the 2nd one, if the hotkey is pressed.

I need to have a function the will "Return" if a hotkey is pressed.

Posted

Hi,

Does anyone know if there is a work around or alternatives to having a function with in a function.

Here is why:

I have created a gui application with menu items.

Every menu item envokes a function.(sends key strokes, etc.)

I need an abort hotkey so that if the user needs to cancel the function they started.

It is impossible to create a hotkey function within an existing function.

Any help is appreciated.

Radsam

<{POST_SNAPBACK}>

Are you looking for something like this? That is, set a global variable inside each function so that a single HotKey will handle tham all.

Global $gsWhichOne = 0

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

While 1

_Func1()

_Func2()

WEnd

Exit

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Escape ()

Select

case $gsWhichOne = 1

; do something

msgbox(4096, "Escape 1", "Escaped from function 1." & @lf & "Press OK to continue.")

case $gsWhichOne = 2

; do something

msgbox(4096, "Escape 2", "Escape from function 2." & @lf & "Press OK to continue.")

EndSelect

EndFunc ; _Escape

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Func1 ()

$gsWhichOne = 1

msgbox(4096, "Function 1", "Function 1" & @lf & "Click OK to call Function 2, or " & @lf & "press the ESC key and then click OK to call the Escape function for function 1")

EndFunc ; _Func1

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Func2 ()

$gsWhichOne = 2

msgbox(4096, "Function 2", "Function 2" & @lf & "Click OK to call Function 1, or " & @lf & "press the ESC key and then click OK to call the Escape function for function 2.")

EndFunc ; _Func2

Phillip

Posted

Maybe something like this? Press Esc to Abort an action.... If you want an Abort button, you need to do a little more work by having each Action function call GuiGetMsg() or something....

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000

$GUI = GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Edit_0 = GuiCtrlCreateEdit("Output of Actions will appear here:" & @CRLF , 10, 110, 370, 200)
$Button_1 = GuiCtrlCreateButton("Action One", 10, 30, 110, 40)
$Button_2 = GuiCtrlCreateButton("Action Two", 140, 30, 110, 40)

Global $ABORT_ACTION = 0
HotkeySet("{Esc}", "Abort")

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
   Case $msg = $Button_1
      ActionOne()
      $ABORT_ACTION = 0;reset
   Case $msg = $Button_2
      ActionTwo()
      $ABORT_ACTION = 0;reset
    EndSelect
WEnd
Exit

Func Abort()
   $ABORT_ACTION = 1
EndFunc

Func ActionOne()
   While Not $ABORT_ACTION
      ToolTip("ActionOne...")
      ControlSend($GUI, "", $Edit_0, "One ")
      sleep(500)
   WEnd
   ToolTip('')
EndFunc

Func ActionTwo()
   While Not $ABORT_ACTION
      ToolTip("ActionTwo...")
      ControlSend($GUI, "", $Edit_0, "Two ")
      sleep(500)
   WEnd
   ToolTip('')
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Posted

Hi,

CyberSlug, your idea is good and works well, however, the code in between the While and WEnd statements have to complete before the $ABORT_ACTION variable is read. This is great if your function is 1 or 2 lines but my functions are much larger than that. I need to stop a function MID-STREAM.

The following is an example of just one of the functions I have. I have more that are 3 or 4 times the size. I need to be able to abort mid-way through a function if necessary. Much like what happens you click on the A3 icon in the sys try.(when you do that, you get an immediate responce)

Func uppercase()
;GUICtrlSetData($statuslabel, "Making clipboard contents uppercase")
    $clip = ClipGet()
    ToolTip($clip)
    Sleep(2000)
    ToolTip('')
    $clip = StringUpper($clip)
    ClipPut($clip)
    ToolTip($clip)
    Sleep(2000)
    ToolTip('')
;GUICtrlDelete($statuslabel)
;$statuslabel = GUICtrlCreateLabel($status, 0, 0, 200, 16, $SS_SIMPLE + $SS_SUNKEN)
EndFunc  ;==>uppercase

I appreciate all the help! Any other ideas? :idiot:

Radsam

Posted

I don't know of any way to stop a function mid-stream :idiot: Might be something for the Idea Lab

Here's a workaound that gets ugly fast:

Func uppercase()
;GUICtrlSetData($statuslabel, "Making clipboard contents uppercase")
    $clip = ClipGet()
    ToolTip($clip)
If $ABORT_ACTION Then Return
    Sleep(2000)
    ToolTip('')
If $ABORT_ACTION Then Return
    $clip = StringUpper($clip)
    ClipPut($clip)
    ToolTip($clip)
If $ABORT_ACTION Then Return
    Sleep(2000)
    ToolTip('')
;GUICtrlDelete($statuslabel)
;$statuslabel = GUICtrlCreateLabel($status, 0, 0, 200, 16, $SS_SIMPLE + $SS_SUNKEN)
EndFunc ;==>uppercase
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Posted

You know what? Your idea was exactly what I was was thinking too. However it is really going to suck to put that IF/THEN statement every 1 or 2 lines in my functions. Oh well, at least it will work.

Thanks alot for all the help!

BTW, CyberSlug, your Gui Design app is really good. I can't wait until it's finished!

L8tr

Radsam

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