Jump to content

Trying to set up a toggle


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...