Jump to content

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

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

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.

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

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

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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jamestay97
      Hello! Thanks you for looking at my post
      **No source code I'm sorry work related can't copy information**
      I've been using autoit for about 1 year. 
      I'm having trouble automating a click on an internet explorer web page and I've tried a lot of examples from help pages and forums already. The object I'm trying to click on isnt always in the same spot so I can't use mouse click or control click, I have tried to use the different get collection options and clickbyname, or index or get object. I'm just struggling. 
      Description of object I'm trying to click -- 
      HTML Code looks like <a ng-click.. "Click Here" it appears it's just a click able object named "click here" that opens a hidden window by running a script inside the web page. I'm not able to grab the information from the window unless it's open so I have to automate this click somehow. 
       
      I understand it's difficult to assist without having something to look at, I apologize for that sincerely and appreciate and assistance and suggestions. 
    • By kingjacob90
      Hi
      So I am trying to click the green button, this button is not always in the same place. So fare I am trying to click it by finding the color but there is also something else with the same color on the screen (circled in yellow) that is causing issues. Is there a way to use the Title and Class of the window (can't be just the window as there are more than one with the same name).
      How does AutoIt Info get this information?

    • By adjist
      Hello all! 
       
      Getting this error :
      (22) : ==> Variable used without being declared.: if $vNumber = 0 Then if ^ ERROR  
      But I'm sure I have defined the variable, as in the top of my script has 
      Global $vNumber = 0  
      How would I go about fixing this?
       
    • By MarkIT
      Hi AutoIT masters,
      Good day! Sorry to have bothered this forum but we really need help. We are working on an automation project that is running on VDI server. The BOTS are in .exe are running fine until AV detected them and deleted the files. The files were re-compiled and AV kept on deleting them. The copy of the .exe BOT deleted were sent to Symantec for whitelisting. After whitelisting, it is no longer deleted but no longer working as designed (showing Line script error). We checked the scripts and there were no issues since we run it using SciTE editor and it performed the desired task. Good thing we found on this thread the solution using .a3x and the BOTS worked fine and no longer deleted. Now, the problem is they are asking why the BOTS won't run in .EXE and what is the reason behind Symantec AV deleting them. We raised a case with Symantec but they cannot provide further information as they are always seeing the file as "False Positive". We even tested with Symantec turned off and those .EXE files are working fine, however, after re-enabling, it got deleted.
      Just seeking help on how to better convince them that it is really Symantec causing the issue and the .a3x file.
    • By AutoitMike
      Scite 3.4.4
      Win 10
      I click "Help" or press F1, there is no response
      If I use the file explorer and double click Autoit.chm or Autoit3.chm help opens.
      There is no dialog to check or uncheck "Always ask before opening this file" when clicking on these files.
       
      If you are curious as to why I dont have the latest version, I am creating a back up laptop that has a VERY extensive automation application that I have written over the past 15 years.
       
      An extremely potent, powerful, needed function has been deleted in the upgrade of Autoit in recent years that I can not do without. If my main laptop dies, which it almost did, I am in a very bad position. So I bought the exact same laptop and I am "cofiguring" it to work exactly the same as my main laptop. However, this one has been "Upgraded" to Win 10 which I hope is not the problem. 
      Thanks for any help
×
×
  • Create New...