Jump to content

function stop


CmeC
 Share

Recommended Posts

HotKeySet ("{F5}", "a"   )
HotkeySet ("{F6}", "Stop"   )
HotKeySet ("{F4}", "b"  )
;********** a **********
Func a ()
While (1)

Send ("1")
Sleep (99)
Send ("2")
Sleep (99)
Send ("3")
Sleep (99)

WEnd
EndFunc

;********** b **********
Func b ()
    while (1)
        
        Send ("4")
        Sleep (45)
        Send ("5")
        Sleep (45)
        
        
    WEnd
EndFunc

;********** Stop **********

; Stops The Program.

Func Stop ()

While 1 = 1
Sleep (1000)
Wend

EndFunc


;********** Repeater **********

; Continuous Loop Of Program.

While (1)
Sleep (5000)
WEnd

hello, i have trouble with simple function stoping

function a stops

but function b doesn't

how to make "b" stop? (or both on same time)

Link to comment
Share on other sites

You are missing a mechanism to exit your while loops. All your stop() function does is loop and wait forever.

If you actually want your stop function to stop the program, it should for example have the statement "exit" instead of just waiting forever.

Another way would be to have a file-level variable that you set to true in your Stop() function. Your other functions then should check for the value of your file-level variable, and if set to true, exit your loops.

Example:

Dim $bDone = False  ; file-level variable used as flag
HotKeySet ("{F5}", "a"   )
HotkeySet ("{F6}", "Stop"   )
HotKeySet ("{F4}", "b"  )

Func Stop()
$bDone = True
endfunc

Func a()
While Not $bDone  ; this loop will exit as soon as $bDone is true
   ; do things
Wend
endfunc

Func b()
While Not $bDone  ; this loop will exit as soon as $bDone is true
   ; do things
Wend
endfunc

Good luck!

Edited by rodent1
Link to comment
Share on other sites

tnx

what "Dim" does? (sorry im new here)

1 more thing

is there some kind of priority for program?

when i use first function sometimes it misses (dont press 1 or 2 or3) even if i use larger delays

Link to comment
Share on other sites

Ask the Help file. The Help file knows. ;)

(sorry im new here)

i red it

Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)

and i cant understand it..

1 question more occured

if i try to implement _ispressed nothing happens

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("04", $dll) Then
    
Send ("1")
Sleep (99)
Send ("2")
Sleep (99)
Send ("3")
Sleep (99)

        ExitLoop
    EndIf
WEnd

when i press middle mouse (wheel) function doesn't send 1-2-3

how to implement _ispressed to script correctly?

Edited by CmeC
Link to comment
Share on other sites

Make the sleep much shorter, right now the way you have it written, the script sleeps for 1/4 second every time through the loop and won't see any key/mouse presses. Try it with Sleep(10), should work much better.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The statement

Dim $bDone = False

tells autoit to use a value named $bDone and give it the value "false".

Because it's outside of a function, it can be seen and changed from each function in your script.

If that line had been inside the a() function, the $bDone value would only be accessible from inside that function (accessible means that its value could be read or changed). That's the "scope". Being outside the functions, it's accessible from anywhere inside the file, which is why I called it a "file-level" variable.

So inside the Stop() function, you can change its value to "true". And if that happens while the a() or b() functions are running, before running the statements inside the while loop again, AutoIT evaluates "Not $bDone" and finds it to be "false". At that point, the while loop quits running, and your a() or b() function stops running.

I hope that helps.

Edited by rodent1
Link to comment
Share on other sites

HotKeySet example from the help file.

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

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here ;;;;
While 1
Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func Terminate()
Exit 0
EndFunc

Func ShowMessage()
MsgBox(4096,"","This is a message.")
EndFunc

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Make the sleep much shorter, right now the way you have it written, the script sleeps for 1/4 second every time through the loop and won't see any key/mouse presses. Try it with Sleep(10), should work much better.

Reduce the Sleep variable to 10, the script will run the If line more often. See, your script will work at 250, but you will probably have to hold the button down longer or click it more in order for it to be seen.

thank U wery much

reduced it to 10, took out the exit loop, ant it work almost perfectly, need only to ajust speeds with key send, ant it would be perfect, tnx alot

is there a way to call my functions if _ispessed (11) = ctrl or shift ir alt,

when i try with those keys it doesnt switch between 1-2-3 just hungs on one of them (sends 1,2,3, and then stops, how to loop it?)

p.s. sorry for really newbie questions, just started trying to understand how every thing works, when i will finish with this one, i think i will continue on exploring program and there will be way more questions

Edited by CmeC
Link to comment
Share on other sites

is there a way to call my functions if _ispessed (11) = ctrl or shift ir alt,

I'm not reading this the way you're saying it. Maybe this link to the _IsPressed function in the Help file will help.

when i try with those keys it doesnt switch between 1-2-3 just hungs on one of them (sends 1,2,3, and then stops, how to loop it?)

Again, I don't think I'm reading this the way you intended it to be. You can read about Loop Statements in the Help file though.

Since I've just been pointing you to the Help file, might I just suggest you read the whole thing, several times maybe. It's well written, and has example code written in it for just about every native AutoIt function. There's a couple tutorials in there and more on the wiki. Please continue to ask questions as well, the community here is great about offering help to others who show they've helped (or even are just trying to help) themselves.. A good example would be to post a bit of code you're having trouble with..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

I'm not reading this the way you're saying it. Maybe this link to the _IsPressed function in the Help file will help. Again, I don't think I'm reading this the way you intended it to be. You can read about Loop Statements in the Help file though. Since I've just been pointing you to the Help file, might I just suggest you read the whole thing, several times maybe. It's well written, and has example code written in it for just about every native AutoIt function. There's a couple tutorials in there and more on the wiki. Please continue to ask questions as well, the community here is great about offering help to others who show they've helped (or even are just trying to help) themselves.. A good example would be to post a bit of code you're having trouble with..

#include <misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 10 )
    If _IsPressed("11", $dll) Then

Send ("1")
Sleep (40)
Send ("2")
Sleep (30)
Send ("3")
Sleep (50)


    EndIf
WEnd

when i press control (ctrl (left corner =])) it should make 1-2-3-1-2-3-and so on, but with control pressed it makes 1-2-3 (and then starts working wery slow (like 1 send per 20-30 sec) first time i posted i didnt tried to hold ctrl for so long, so i thought it has stoped

Edited by CmeC
Link to comment
Share on other sites

Huh. I didn't even know one could use a key like that on it's own. Now I know ALT can do stuff on it's own, but I thought CTRL was just a modifier.

if i leave like i was planing to _ispressed (04) (mouse wheel)

it will take 4 keys to hold + problem with ctrl, so i tried puting it in 3 keys, but still there's a problem

any 1 know hot to make it happen? or how to make script that holds down ctrl while moving around other functions?

tnx for your time

Edited by CmeC
Link to comment
Share on other sites

  • 2 weeks later...

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...