Jump to content
Sign in to follow this  
Scoboose

Trying to set up a toggle

Recommended Posts

Scoboose

Can anyone tell me what i am doing wrong?

#cs ----------------------------------------------------------------------------
Esc - Quits
#ce ----------------------------------------------------------------------------

Global $neverendloop = -1
Dim $a

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

While 1
    Sleep(1000)
      MsgBox(0, "Info", "Just a simple clicker ")
        Do 
        Sleep(1000)
        Until $neverendloop > 1
        Sleep(1000)
    WEnd
    
$a = 2

; Toggle run/pause
Func Toggle()
 If $a = 1 Then 
     $a = 2 
 Else
     $a = 1
     EndIf
EndFunc

While $a = 1
MouseClick("Left")
Sleep(1000)
WEnd

Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites
P0ZiTR0N

and what do you try to do?

MouseClick Syntaxis:

MouseClick ( "button" [, x, y [, clicks [, speed ]]] )

Edited by P0ZiTR0N

Share this post


Link to post
Share on other sites
Scoboose

trying to make it so when i press "n" it will click every sec until i press "n" again So "n" turns it on and off

Share this post


Link to post
Share on other sites
Mat

Can anyone tell me what i am doing wrong?

While $a = 1
MouseClick("Left")
Sleep(1000)
WEnd
here it runs through and ends....

should be more like

While 1
If $a = 1 Then MouseClick("Left")
Sleep(1000)
WEnd

I end up with a full code more like this:

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

MsgBox(0, "Info", "Just a simple clicker ")
    
$a = 2

While 1
If $a = 1 Then MouseClick("Left")
Sleep(1000)
WEnd

Func Toggle()
If $a = 1 Then
     $a = 2
Else
     $a = 1
     EndIf
EndFunc


Func Terminate()
    Exit 0
EndFunc
Edited by mdiesel

Share this post


Link to post
Share on other sites
qazwsx

Look in the help file; there is an example of a toggle. You are not understanding how the program flows.

Edited by qazwsx

Share this post


Link to post
Share on other sites
Mat

...no it doesn't...

while 1 is a neverending loop.

try it. mine works exactly as you want it to.

Edited by mdiesel

Share this post


Link to post
Share on other sites
Scoboose

...no it doesn't...

while 1 is a neverending loop.

try it. mine works exactly as you want it to.

Thank you

Share this post


Link to post
Share on other sites
Jfish

Thank you

Try this:

CODE
HotKeySet("{ESC}", "Terminate")

HotKeySet("n", "Toggle")

MsgBox(0, "Info", "Just a simple clicker ")

$a = 1

While 1

If $a = 1 Then

MouseClick("Left")

Sleep(1000)

Else

Terminate()

EndIf

WEnd

Func Toggle()

If $a = 1 Then

$a = 2

Else

$a = 1

EndIf

EndFunc

Func Terminate()

Exit 0

EndFunc


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Melba23

Scoboose,

Using a Boolean variable makes the toggle much simpler:

#cs ----------------------------------------------------------------------------
    Esc - Quits
#ce ----------------------------------------------------------------------------

Global $fToggle = True

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

While 1
    While $fToggle
        ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")
        Sleep(1000)
    WEnd
WEnd

; Toggle run/pause
Func Toggle()
    $fToggle = Not $fToggle ; <<<<<<<<<<<<  really simple syntax!
EndFunc  ;==>Toggle

Func Terminate()
    Exit
EndFunc  ;==>Terminate

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mat

"Try this:"

its mine just starts activated.

@Scoboose

Please test before answering in the future... I've done it before too, and its not pretty. It usually ends up with you being proved wrong by someone, which is not good.

Theres also always someone to come out with a better method right at the end...***Melba23***

hope it goes well

MDiesel

Share this post


Link to post
Share on other sites
Scoboose

Scoboose,

Using a Boolean variable makes the toggle much simpler:

#cs ----------------------------------------------------------------------------
    Esc - Quits
#ce ----------------------------------------------------------------------------

Global $fToggle = True

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

While 1
    While $fToggle
        ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")
        Sleep(1000)
    WEnd
WEnd

; Toggle run/pause
Func Toggle()
    $fToggle = Not $fToggle; <<<<<<<<<<<<  really simple syntax!
EndFunc ;==>Toggle

Func Terminate()
    Exit
EndFunc ;==>Terminate

M23

I don't understand any of that lol. sorry

Share this post


Link to post
Share on other sites
Scoboose

What if i want it to do more then just left click? this will continue to press "c" and i don't want it to

Dim $a

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")


      MsgBox(0, "Info", "Press the N key to toggle Gathering. Press Esc to quit macro. ")

$a = 2

While 1
If $a = 1 Then MouseClick("left") 
    Sleep(125)
    Send("c") 
    sleep(1000)
WEnd

Func Toggle()
 If $a = 1 Then 
     $a = 2 
 Else
     $a = 1
     EndIf
 EndFunc
 
Func Terminate()
    Exit 0
EndFunc
Edited by Scoboose

Share this post


Link to post
Share on other sites
Melba23

Scoboose,

OK, a Boolean variable can only be 'True' or 'False' - which for a toggle is just what you want. So the 'Toggle' function changes the value of the $fToggle variable by using Not:

Not True = False

Not False = True

Easy, no?

Here is a commented version:

; Set the toggle to True
Global $fToggle = True

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

While 1
    While $fToggle; If the toggle is True then do this - if it is False then do not You could also write  'If $fToggle = True' here - it means the same thing
        ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")
        Sleep(1000)
    WEnd
WEnd

; Toggle run/pause
Func Toggle()
    $fToggle = Not $fToggle  ; Change the toggle as explained above
EndFunc;==>Toggle

Func Terminate()
    Exit
EndFunc;==>Terminate

Boolean variables are not easy to understand, but are well worth the trouble as they can really make your life easy in certain circumstances - like toggles! :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Scoboose

Scoboose,

OK, a Boolean variable can only be 'True' or 'False' - which for a toggle is just what you want. So the 'Toggle' function changes the value of the $fToggle variable by using Not:

Not True = False

Not False = True

Easy, no?

Here is a commented version:

; Set the toggle to True
Global $fToggle = True

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

While 1
    While $fToggle; If the toggle is True then do this - if it is False then do not You could also write  'If $fToggle = True' here - it means the same thing
        ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")
        Sleep(1000)
    WEnd
WEnd

; Toggle run/pause
Func Toggle()
    $fToggle = Not $fToggle; Change the toggle as explained above
EndFunc;==>Toggle

Func Terminate()
    Exit
EndFunc;==>Terminate

Boolean variables are not easy to understand, but are well worth the trouble as they can really make your life easy in certain circumstances - like toggles! :-)

M23

Ok i sort if get it so a Boolean variable is like a on off switch it can only be on or off, right?

and $fToggle = Not $fToggle means change it from what it is to what it is not, right?

now what is all this? ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")

sorry i am new the whole scripting thing ^_^ but i like to think i can learn

Edited by Scoboose

Share this post


Link to post
Share on other sites
Scoboose

Hey i got it ^_^

Thank you guys

HotKeySet("{ESC}", "Terminate")
HotKeySet("n", "Toggle")

Global $fToggle = False

While 1
While $ftoggle = True
    MouseClick("left") 
    Sleep(125)
    Send("c") 
    sleep(1000)
    WEnd
WEnd

Func Toggle()
 $ftoggle = Not $ftoggle
 EndFunc
 
Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites
Melba23

Scoboose,

ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")

ConsoleWrite sends text to the lower window of SciTE - here it is sending the word "MouseClick" followed by the actual msec count so you can see that the MouseClicks are different and happen once a second.

; begins a comment - everything after it is ignored by AutoIt. So I can tell you that I am using this line in place of your MouseClick (basically because you cannot see a mouse click!) and Autoit does not think I am trying to tell it something instead.

If you are very new to scripting with Autoit, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Scoboose

Scoboose,

ConsoleWrite("MouseClick " & @SEC & @CRLF); In place of MouseClick("Left")

ConsoleWrite sends text to the lower window of SciTE - here it is sending the word "MouseClick" followed by the actual msec count so you can see that the MouseClicks are different and happen once a second.

; begins a comment - everything after it is ignored by AutoIt. So I can tell you that I am using this line in place of your MouseClick (basically because you cannot see a mouse click!) and Autoit does not think I am trying to tell it something instead.

If you are very new to scripting with Autoit, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here.

M23

TYVM

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.