Jump to content

Function starting function


Recommended Posts

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

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 

 

HotKeySet('{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 by SevenScript
Link to comment
Share on other sites

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:

  1. Send('2')
  2. Send('w') continuously until you press NumLock again:
  3. Send('4')

Then repeat?

 

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

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:

  1. Send('2')
  2. Send('w') continuously until you press NumLock again:
  3. 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 by SevenScript
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...