Jump to content

Loop To Delete GUI


Recommended Posts

Hello, I am very new to AutoIt, and I'm making a simple GUI autoclicker. I made 2 loops, one for handling the interval the mouse clicks, and one for when the user closes the box. How do I get it so it reaches the other loop, since it doesn't get reached to?

 

Script:

#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hDLL = DllOpen("user32.dll")
Local $Speed

Local $hGUI = GUICreate("Autoclicker", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, $WS_EX_ACCEPTFILES)
Local $clickspeed = GUICtrlCreateInput("Speed/Interval", 10, 5, 300, 20)
GUISetState(@SW_SHOW, $hGUI)

While 1
    $Speed = GUICtrlRead($clickspeed, $GUI_READ_EXTENDED)
    If _IsPressed("4A", $hDLL) Then
    MouseClick($MOUSE_CLICK_LEFT)
    Sleep($Speed)
    ElseIf _IsPressed("4B", $hDLL) Then
    MsgBox($MB_OK,"Autoclicker","Stopped autoclicker",10)
    ExitLoop
    EndIf
WEnd


While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
  WEnd
   GUIDelete($hGUI)

 

Link to comment
Share on other sites

I don't think I can edit the post, but I wasn't thinking. I put the second loop for handling when the user closes the GUI in the first one, but it closes when I open it.

 

#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hDLL = DllOpen("user32.dll")
Local $Speed

Local $hGUI = GUICreate("Autoclicker", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, $WS_EX_ACCEPTFILES)
Local $clickspeed = GUICtrlCreateInput("Speed/Interval", 10, 5, 300, 20)
GUISetState(@SW_SHOW, $hGUI)

While 1
    $Speed = GUICtrlRead($clickspeed, $GUI_READ_EXTENDED)
    If _IsPressed("4A", $hDLL) Then
    MouseClick($MOUSE_CLICK_LEFT)
    Sleep($Speed)
    ElseIf _IsPressed("4B", $hDLL) Then
    MsgBox($MB_OK,"Autoclicker","Stopped autoclicker",10)
    ExitLoop
    EndIf
    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
   GUIDelete($hGUI)
WEnd

 

Link to comment
Share on other sites

i guess that, first you want to set interval value and after that make clicks.

So here you go

#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hDLL = DllOpen("user32.dll")
Local $Speed = Null

Local $hGUI = GUICreate("Autoclicker", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, $WS_EX_ACCEPTFILES)
Local $clickspeed = GUICtrlCreateInput("Speed/Interval", 10, 5, 300, 20, 0x2000) ;0x2000 -> Allows you to enter a numbers only
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE ; exit button click event
            $Speed = GUICtrlRead($clickspeed) ;$GUI_READ_EXTENDED nothing change here (see help file); $speed contain value of input
            GUIDelete($hGUI) ;Delete gui after exit the window
            ExitLoop ;Exit the loop
    EndSwitch
    Sleep(20) ;Not to burden the CPU
WEnd

While 1
    If _IsPressed("4A", $hDLL) Then
        MouseClick($MOUSE_CLICK_LEFT) ;you can also add coords to click (x,y)
        Sleep($Speed)
    ElseIf _IsPressed("4B", $hDLL) Then
        MsgBox($MB_OK,"Autoclicker","Stopped autoclicker",10) ;Exit script after press K key
        Exit ;Exit the script
    EndIf
WEnd

EDIT:

chcek this MouseClick Function

You have to know that, after click J key, the script simulate mouse click left button, but only once and after that script "sleep" for interval that you set (Script is unavailable)
If you want to set more clicks using interval you need use loop

for example: 

For $i = 0 To 9 Step +1
    MouseClick("",Default,Default)
    Sleep($Speed)
Next

;10 clicks with a break (value of $Speed) after each click in current mouse position (2nd and 3rd parameter are coords that you can set - default is current x,y cursor position)

;OR

MouseClick("",Default,Default,10) ;10 clicks without any break

 

One more. If you allow others using your script, use $MOUSE_CLICK_PRIMARY instead of $MOUSE_CLICK_LEFT. This is a better approach as it takes into account left/right handed users.

Edited by Jarzyn
Bad thinking

Sorry for my english :)

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