SevenScript Posted February 23, 2023 Share Posted February 23, 2023 Hello, have a little question for you, How can i start function with another function? Example HotKeySet("{F1}", "open") HotKeySet("{F2}", "close") Func open() ; send("Example") sleep(2000) **Run function Close*** ; ---> Don't know how EndFunc Func close() ; send("StillExample") sleep(2000) **Run function open*** ; ---> Don't know how EndFunc Link to comment Share on other sites More sharing options...
Danp2 Posted February 23, 2023 Share Posted February 23, 2023 If you do what you are proposing, it will result in an endless loop where open() calls close(), which then calls open(), ad nauseam. This will likely cause Autoit to crash. I suggest that you provide a more detailed description of what you are hoping to accomplish. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
SevenScript Posted February 23, 2023 Author Share Posted February 23, 2023 (edited) Okey then, So have a script which Send 2 and 4 when i pressing NumLock. Want to have one more option in that. When i press down arrow(Enable) Then NumLock working like: *Numlockclick* -> Gives 2x {down} ; Disabled/Enabled and 2 *2ndNumlockClick* -> Gives 4 and {up} Start pressing button *3rd NumlockClick* -> Gives 2x {down} Disabled/Enabled -> Pausing but prepare for another numlock and 2 But i doesn't work properly. After Numlock 1st click it's okey -> 2nd click also Okey and it starts pressing. But 3rd numlock doesn't stop ( Enabled doesn't work) and have to stop manualy with down arrow ------------------------- i used in _Bind function send(up} and send{up} to run another function, but it doesn't work expandcollapse popupHotKeySet('{numlock}', '_Bind') Global $bIsDown = False Local $Enabled, $SleepTime Func _Bind() $bIsDown = Not $bIsDown If $bIsDown Then send("{down}") sleep(20) send("{down}") sleep(20) send("2") ; 2 starts another program for 1 minute Return EndIf send("4") ; 4 stops that program sleep(20) mouseup("left") sleep(20) send("{up}") EndFunc Enabled() Func Enabled() if $Enabled = True Then $Enabled = False $SleepTime = 1000 Else $Enabled = True $SleepTime = 10 HotKeySet("{down}", "Enabled") HotKeySet("{up}", "Pressing") EndIf EndFunc Func Pressing() ; While $Enabled send("w") sleep(10) WEnd EndFunc while 1 sleep(200) WEnd Edited February 23, 2023 by SevenScript Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 24, 2023 Share Posted February 24, 2023 First of all, Send can trigger HotKeys, so I strongly recommend that you don't set hotkeys that are likely to be in data that you're Send'ing. So use a key like {HOME}, {F1}, etc. Your {down} and {up} will get triggered by your Sends, and you'll have no idea what state your script is in. I get that this seems to be the only way that you're familiar with how to call a function, but it's just a very poor way to do it. HotKeySet should only be used for user interaction. Secondly, for your first question, I strongly recommend that you read a tutorial on using AutoIt, since what you're asking for is very basic: https://www.autoitscript.com/wiki/Tutorials But to show you an example: Func1() Func Func1() Local $sFunc2Msg = Func2() MsgBox(0, 'Func1', 'Message from Func2 after being called from Func1: ' & @CRLF & @TAB & $sFunc2Msg, 10) EndFunc ;==>Func1 Func Func2() Local $sMsg = 'This is Func2, reporting in' MsgBox(0, 'Func2', $sMsg, 5) Return $sMsg EndFunc ;==>Func2 Exit I believe that the functionality that you're after (doing a different thing each time you press the button) is what I put in my post on your other topic here: If that's not what you're looking for it, it would be good to explain what you want to do, ignoring anything that you've currently tried (give us the idea). Are you looking for something like this, where each time you press NumLock this happens: Send('2') Send('w') continuously until you press NumLock again: Send('4') Then repeat? SevenScript 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
argumentum Posted February 24, 2023 Share Posted February 24, 2023 ..you could change the logic by setting a Global $iActive and run it from the main loop SevenScript 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
SevenScript Posted February 24, 2023 Author Share Posted February 24, 2023 (edited) 9 hours ago, mistersquirrle said: If that's not what you're looking for it, it would be good to explain what you want to do, ignoring anything that you've currently tried (give us the idea). Are you looking for something like this, where each time you press NumLock this happens: Send('2') Send('w') continuously until you press NumLock again: Send('4') Then repeat? 1. Disable*/Enable Target so it can be used in point2. and Send('2') //// * Disable also stops point2 2.Send('4') and Start Target ( pressing w ) And then repeat yes But Today i solved Func _Bind() $bIsDown = Not $bIsDown If $bIsDown Then send("{down}") sleep(20) sleep(20) send("2") ; 2 starts another program for 1 minute Return EndIf send("4") ; 4 stops that program sleep(20) mouseup("left") sleep(200) send("{down}") sleep(200) send("{up}") sleep(200) EndFunc Yesterday i was doing in autoit for many hours and my mind was pretty tired, After some sleep my mistake was pretty easy to find, Thank you for answers and for supporting newbies. Edited February 24, 2023 by SevenScript 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