Jump to content

Restart a function and exit previous call


Cue
 Share

Recommended Posts

what is the best way of restarting a function if the hotkey is pressed again during a sleeptime within that function. eg gui turns three different colours if pressed again colours start from begining

I currently have this but i dont think this is the best way. any ideas?

#include <GUIConstants.au3>
$window_h=0
$PressfNOTfinished=0
HotKeySet("1","keypressed")

While 1
    sleep(20)
WEnd

Func keypressed()
    
    $PressfNOTfinished=1
    
    GUIDelete($window_h)
    $window_h=GUICreate ( "test", 300, 300, 0, 0, $WS_POPUPWINDOW, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW )
    
    GUISetBkColor(0x0000FF,$window_h)
    Sleep(2000)
    
    if $PressfNOTfinished Then
        
        GUISetBkColor(0x00FF00,$window_h)
        Sleep(2000)
        
        If $PressfNOTfinished Then
            
            GUISetBkColor(0xFF0000,$window_h)
            Sleep(2000)
            
        EndIf
        
    EndIf
    
    $PressfNOTfinished=0

EndFunc
Link to comment
Share on other sites

thanks darkshadow but ive already seen that topic I actually posted on that topic :lmao: . That doesnt actually do what i want it still continues the function if its called again during the sleep time.

Link to comment
Share on other sites

Any Ideas anyone??

Here is a proposal with a few improvements

1 for each new window I change the location so as to see clearly if the preceding one is suppressed.

function keypress is the proposal with inside a msgbox that is used to track what the keypress do :

it stops the function execute the call (maybe it's stopped also by a following keypress and when the function is finished the waiting functions resume where they were stopped, in the opposite order as their launch.

function keypress3 is the simple version of what you want to do

#include <GUIConstants.au3>
HotKeySet("1","keypressed")
HotKeySet("f","Finir")

$decal=0

While 1
    sleep(20)
WEnd

Func Finir()
    Exit
EndFunc


Func keypressed()
    global $numLastCall
    local $numCall
    $numLastCall=$numLastCall+1
    $numCall=$numLastCall
    
    GUIDelete()
    $decal=$decal+20
    GUICreate ( "test", 300, 300, $decal, $decal, $WS_POPUPWINDOW, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW )
    GUISetState()
    GUISetBkColor(0x0000FF)
    Sleep(2000)
    if $numCall<$numLastCall then 
        msgbox(0,"","Window N°" & $numCall & @CRLF & "Exit on line N°" & @ScriptLineNumber)
        Return
    EndIf
    GUISetBkColor(0x00FF00)
    Sleep(2000)
    if $numCall<$numLastCall then 
        msgbox(0,"","Window N°" & $numCall & @CRLF & "Exit on line N°" & @ScriptLineNumber)
        Return
    EndIf
    GUISetBkColor(0xFF0000) 
    MsgBox(0,"","Window N°" & $numCall & " finished")
EndFunc

Func keypressed3()
    global $numLastCall
    local $numCall
    $numLastCall=$numLastCall+1
    $numCall=$numLastCall
    
    GUIDelete()
    $decal=$decal+20
    GUICreate ( "test", 300, 300, $decal, $decal, $WS_POPUPWINDOW, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW )
    GUISetState()
    GUISetBkColor(0x0000FF)
    Sleep(2000)
    if $numCall<$numLastCall then Return
    GUISetBkColor(0x00FF00)
    Sleep(2000)
    if $numCall<$numLastCall then Return
    GUISetBkColor(0xFF0000) 
EndFunc
Link to comment
Share on other sites

Cue try this. Basically I just set the hotkey again in the function.

Kohr

#include <GUIConstants.au3>
$window_h = 0
$PressfNOTfinished = 0
HotKeySet("{HOME}", "keypressed")
HotKeySet("{ESC}","CloseClicked")

While 1
    Sleep(20)
WEnd

Func keypressed()
HotKeySet("{HOME}", "keypressed")
    $PressfNOTfinished = 1
    GUIDelete($window_h)
    $window_h = GUICreate("test", 300, 300, 0, 0, $WS_POPUPWINDOW, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    GUISetState()
    GUISetBkColor(0x0000FF, $window_h)
    Sleep(2000)
    If $PressfNOTfinished Then
        GUISetBkColor(0x00FF00, $window_h)
        Sleep(2000)
        If $PressfNOTfinished Then
            GUISetBkColor(0xFF0000, $window_h)
            Sleep(2000)
        EndIf
    EndIf
    $PressfNOTfinished = 0

EndFunc   ;==>keypressed

Func CloseClicked()
    Exit
EndFunc   ;==>CloseClicked
Edited by Kohr
Link to comment
Share on other sites

thanks for the help everyone.I didnt think of using return :">

if i were to press it 20 times it will still do the conditional statement

if $numCall<$numLastCall then Return

20 times(if im not mistaking).

i was wondering if there was some ingenius way of making it do it only once.

khor what happens if you put

HotKeySet("{HOME}", "keypressed")

inside the function

does this solve the above problem?

Link to comment
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
 Share

  • Recently Browsing   0 members

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