Cue Posted October 14, 2006 Posted October 14, 2006 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
darkshadow791 Posted October 14, 2006 Posted October 14, 2006 Take a look at http://www.autoitscript.com/forum/index.php?showtopic=25688 Note Taker Lite - a note taking / converting tool.
Cue Posted October 14, 2006 Author Posted October 14, 2006 thanks darkshadow but ive already seen that topic I actually posted on that topic . That doesnt actually do what i want it still continues the function if its called again during the sleep time.
Cue Posted October 17, 2006 Author Posted October 17, 2006 Any Ideas anyone??it seems that Kohr is looking for something similarhttp://www.autoitscript.com/forum/index.php?showtopic=34659
tresa Posted October 18, 2006 Posted October 18, 2006 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 expandcollapse popup#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
Kohr Posted October 18, 2006 Posted October 18, 2006 (edited) 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 October 18, 2006 by Kohr AutoIt LinksAutoIt CrapsGrid_PixelSearchAdvancedPixelGrab
Cue Posted October 20, 2006 Author Posted October 20, 2006 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?
Kohr Posted October 23, 2006 Posted October 23, 2006 khor what happens if you put HotKeySet("{HOME}", "keypressed")inside the function does this solve the above problem?The code I posted solves what you needed in the 1st post. Did you try it?Kohr AutoIt LinksAutoIt CrapsGrid_PixelSearchAdvancedPixelGrab
Cue Posted October 24, 2006 Author Posted October 24, 2006 sorry if this is a stupid question but how does the way the code is executed differ if you set the hotkey inside the function again.
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