Jump to content

Autoit Perform Variable


Atoxis
 Share

Recommended Posts

Howdy, this is my first post, massive fan of autoit. 
I've searched and tried and I would just like people who are better at this than me to let me know if this is even a thing.

I'd like to perform just a variable. For example, it would be. *see inserted code*
So what i'm wanting is, create the constant $test, and that variable would be what is followed after the = . Then perform the _FileCreate. Then perform the variable.  Logically or in my head rather.. That variable is declared and is equal to what it is set to above, therefore just placing the variable plainly in the script, it should be equal to what it was declared as.  So what am I doing wrong, and or how can I have autoit just perform the variable.  


 

#include <File.au3>
Const $test = FileWriteLine(@DesktopDir & "\Log.txt", @CRLF )


_FileCreate(@DesktopDir & "\Log.txt")



$test

 

Link to comment
Share on other sites

The variable stores what is assigned to it. If you assign a function to a variable it only stores the return value of that function.

For what you want to do it would be best to make your own function and call it using its name. If you really want to use a variable you could assign the name of the function to the variable and call it using the Call() function.
Here is an example:

#include <File.au3>

_FileCreate(@DesktopDir & "\Log.txt")
$test = "name_of_func"

Call($test)

Func name_of_func()
    FileWriteLine(@DesktopDir & "\Log.txt", @CRLF )
EndFunc

Now you can call the function as often as you want using Call($test).

Hope it helps!

Link to comment
Share on other sites

That'll work, appreciate it very much!

Now I'm working on pauses. If you open the tray icon it'll pause the script universally (wherever the script is currently at in its run).  << Which is utterly amazing. Looking for a way to tap into that because it's exactly that, a universal pause/sleep that i'd like to bind to a hotkey.

Again, thank you!

Link to comment
Share on other sites

Interesting task, maybe something like this would be what you're looking for?

Global $bPause = False
AdlibRegister("_pause")
HotKeySet("{ESC}", "_toggle_pause")


While 1
    ConsoleWrite("Not paused" & @CRLF)
    Sleep(50)
WEnd


Func _pause()
    While $bPause = True
        ConsoleWrite("Paused..." & @CRLF)
        Sleep(50)
    WEnd
EndFunc

Func _toggle_pause()
    $bPause = Not $bPause
EndFunc

 

Edit: I should really learn to read the helpfiles before posting. There is already an example for a pause toggle in the HotKeySet() help:

; Press Esc to terminate script, Pause/Break to "pause"

Global $g_bPaused = False

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(100)
    ConsoleWrite("Script is running..." & @CRLF)
WEnd

Func TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(100)
        ConsoleWrite("Script is paused..." & @CRLF)
    WEnd
EndFunc   ;==>TogglePause

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Edited by Floops
Link to comment
Share on other sites

Let's apply it here.
A text file would be open, and the script would start by writing/sending the number 1, and then incrementing up by 1.
1,2,3,4,5,etc

while the script is doing this, i'd like to be able to press a hotkey that would work not by sleeping, and then ultimately needing me to restart the function again, resulting in starting back at 1.

I'd like to be able to run the above script, and then pause it in place as if I had clicked on the traymenu pause.
so when i'd unpause it via tray menu, the script would continue right where it had left off as if nothing else had happened.


I have school and work tomorrow starting at 8am my time (currently 2:03AM). But i'll keep trying to come up with something or else i'll just sleep and try to code it in my head lol.

Link to comment
Share on other sites

Keep In mind what i'm trying to make this for is something more complicated than sending numbers that can be stored as a var.

Ultimately I want to remote into the computer running the script, and be able to press a hotkey that globally pauses the script in its currently running line.   And be able to unpause it. Same as traymenu pause. And the script carries on as if it had never skipped a line.  I can't find a way to access the traymenu pause outside of actually using the menu.

Edited by Atoxis
Link to comment
Share on other sites

HotKeySet ("{F1}", "Sleeper")
HotKeySet ("{F2}", "start")

start()
Func start()
WinActivate("New Text Document - Notepad", "")

for $start = 0 to 100 Step +1
    Send($start)
    Sleep(500)
Next
EndFunc


Sleeper()
Func Sleeper()
While 1
Sleep(999999)
WEnd
EndFunc

Here I actually test it.
Open up a new note pad, and press F2.  The counter starts.
Pause it by pressing F1.

Test it by either pressing F2, resulting in counting at 0 again; or by pressing F1 to sleep, and pressing F2. The same resulted is achieved for both.

However_____
starting over.
Start the counter, then go and pause the script from the tray icon.
Wait 3 seconds for testing purposes.
now on the tray icon, unpause the script and quickly click in the text box field.
The counter resumes it's number as if it hadn't stopped.

This would be helpful to hotkey toggle that pause in the traymenu.
 

Link to comment
Share on other sites

1 hour ago, TurionAltec said:

Calling a MsgBox will pause the script until it's closed.

That's neat, i'll play with that some and see if I can make that work.

>
I tested it, resulted in starting back at 0 in the counter.  This is starting to make my head hurt.
I just want to use something that's already built in lol.

I also know if I store the number 0 , in the line
for $start = 0 to 100 step +1  as a variable above the function, and in within the for/next, write a +1 to that variable, it would continue on.  But this still wouldn't work in my real scenario that I need.

So final thing is, does anyone know a way to access the global pause that is built into the traymenuPause. And write it as a hotkey.

Edited by Atoxis
Tested
Link to comment
Share on other sites

How about this?

Global $bSleep = False

HotKeySet ("{F1}", "Sleeper")
HotKeySet ("{F2}", "Resume")

start()
Func start()
    WinActivate("New Text Document - Notepad", "")

    for $start = 0 to 100 Step +1
        Send($start)
        Sleep(500)
    Next
EndFunc

Func Resume()
    $bSleep = False
EndFunc

Func Sleeper()
    $bSleep = True
    While $bSleep
        Sleep(10)
    WEnd
EndFunc

 

Link to comment
Share on other sites

Ultimately I don't think it can be done using Sleeps in script, because you're calling out of the function to another function. Unless there's a way to call to a sleep func, and then return back to the exact line where you were at in the script before you called to sleep.  I gave up around 3am. Maybe in future releases they'll let you tap into it.

Link to comment
Share on other sites

Excuse me if I'm missing something here but isn't the code that I posted exactly doing what you are describing?

Once you press F1 it goes into the function Sleeper and stays there until you press F2, then the function Resume is called which allows Sleeper to return exactly where you were before you initially called Sleeper.

Link to comment
Share on other sites

HotKeySet('{ESC}','Quit')
HotKeySet('p','Pause')

While True
   ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & @CRLF)
   Sleep(10)
WEnd

Func Pause()
   Static $Pause = True
   $Pause = Not $Pause
   Do
      Sleep(10)
   Until $Pause
EndFunc

Func Quit()
   Exit
EndFunc

 

When the words fail... music speaks.

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

×
×
  • Create New...