"The code is working fine without any problem"
Then you must have pasted incomplete code. It exits as soon as it starts.
Code: Select all
If State=0
State=Off
else
State=0
SetTimer SendKey, %State%
"If State is 0, then turn the timer off, but if it is non-zero then fire the timer with NO DELAY"
This code is utterly pointless, as
State is uninitialized, so always starts as "", so as "" is not equal to 0, it always turns the timer on at absolute max rate
Code: Select all
SendInput % "{F5}" "{Tab}" "{x}" Sleep(600) "{2}" "{F1}" Sleep(50) "{F4}"
Sleep(t){
Sleep % t
}
This code does not do what you think it does.
SendInput % "{F5}" "{Tab}" "{x}" Sleep(600) "{2}" "{F1}" Sleep(50) "{F4}" DOES NOT sleep in the middle of the send.
Sleep(600) is first executed, it has no return value, so it evaluates to "", and does the sleep at that point (Not mid-send)
Then it sleeps for 50, again no return value.
Then, finally, it sends the string
{F5}{Tab}{x}{2}{F1}{F4} with NO DELAYS in between.
Instead, you want
Code: Select all
Send {F5}{Tab}{x}
Sleep 600
Send {2}{F1}
Sleep 50
Send {F4}
Finally, the script as posted will never, ever do anything useful anyway, as it will exit as soon as it starts. I suspect that this is a snippet of a longer script?
In order for a script to keep running, it must do one of:
The Auto-execute section never ends (eg enters an infinite loop)
Have one or more hotkeys
Have a GUI
Have the directive #Persistent
Your script has none of those, so it will exit straight away.