Sign in to follow this  
Followers 0
CmeC

function stop

15 posts in this topic

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)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Ask the Help file. The Help file knows. ;)
1 person likes this

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.


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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
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.


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

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#15 ·  Posted

bump, still didn't solved problem

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
    • DagSa
      By DagSa
      Try to find a solution for help files to my autoit executable.
      Its installed from simple XP-POS cash computers to desktop with windows 7, 8, 10.
      The compiled AutoIt program itself work everywhere, but the help file??
      I need a help file called from from the program and I don't really know what working best in all OS platforms.
      1. A wordfile is helpful enough, but word is not installed everywhere.
      2. RTF is very big files with pictures.
      3. I could save it as pdf, but not all have it either.
      4. Tried  .MHT file, but downside is browser could cover hole screen if browser closed this way. I have not found any way to resize it to specific size when open up.
      5. Use of IE.au3 lib. Well it could open mht files ,but always got question about use it as default browser or not. Think this also make IE browser lose control so I could not resize.
      6. Look at making a  .CHM file, but I don't think its the future do use that format. (.hlp is no no and old)

      Any tips of do it in autoit or make a call to open up in some nice format working everywhere.
       
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • geekyworld
      By geekyworld
      Hi. I want to read the help file on my Kindle ebook reader (to protect my eyes). Is it available in Kindle or epub format? I tried converting it myself but the results were not very good.
      --Thanks!