Jump to content

Auto Click


Recommended Posts

For now, my script is so half later I plan to add two other options, but first and foremost is not working, what did I do wrong?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Configurações", 250, 300, -1, -1)
$input_time = GUICtrlCreateInput("1", 150, 18, 80, 18)
$separador1 = GUICtrlCreateLabel("______________________________________________", 0, 0, 999, 15)
$abk1 = GUICtrlCreateLabel("Seconds waiting a move to verify (click or not):", 10, 19, 140)
$checkbox1 = GUICtrlCreateCheckbox(" Start", 10, 40, 120, 20)
$separador2 = GUICtrlCreateLabel("______________________________________________", 0, 60, 999)
$abk2 = GUICtrlCreateLabel("Close Window Explanation...", 10, 80, 220, 50)
$checkbox2 = GUICtrlCreateCheckbox(" Close the Window if mouse move to {X}", 10, 128, 200, 20)
$separador4 = GUICtrlCreateLabel("______________________________________________", 0, 150, 999)
$abk3 = GUICtrlCreateLabel("My OPTION2", 10, 170, 200, 32)
$checkbox2 = GUICtrlCreateCheckbox(" Active Shortcut of OPTION2 [Ctrl]", 10, 200, 200, 20)
$separador5 = GUICtrlCreateLabel("______________________________________________", 0, 220, 999)
$ok = GUICtrlCreateButton("Ok", 6, 240, 250-12, 54)
AutoItSetOption("TrayMenuMode", 1)
$pref = TrayCreateItem("Configurações")
$aboutitem = TrayCreateItem("Sobre")
$exit = TrayCreateItem("Sair")
While 1
Local $msg = TrayGetMsg()
Select
  Case $msg = 0
  
   Case $msg = $aboutitem
   TrayItemDelete($aboutitem)
   TrayItemDelete($exit)
   TrayItemDelete($pref)
   $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
   $exit = TrayCreateItem("Sair")
         MsgBox(64, "About:", "Coded by Washington C. Santos")
  Case $msg = $pref
   TrayItemDelete($aboutitem)
   TrayItemDelete($exit)
   TrayItemDelete($pref)
   $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
   $exit = TrayCreateItem("Sair")
   GUISetState(@SW_SHOW)
  Case $msg = $exit
   Exit
    EndSelect
  
    $msg2 = GUIGetMsg()
   Switch $msg2
      Case $GUI_EVENT_CLOSE
         Exit
      Case $ok
   GUISetState(@SW_HIDE)
   start()
   EndSwitch
WEnd
Func start()
   Global $time = $input_time*1000
   If BitAND(GUICtrlRead($checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
   Global $initial_positionx = MouseGetPos(0)
   Global $initial_positiony = MouseGetPos(1)
      Sleep($time)
   If $initial_positionx = MouseGetPos(0) Then
   If $initial_positiony = MouseGetPos(1) Then
      MouseClick("Left", MouseGetPos(0), MouseGetPos(1))
      Sleep($time)
      If $initial_positionx = MouseGetPos(0) Then
         If $initial_positiony = MouseGetPos(1) Then
      WaitMouseMove()
      Else
      EndIf
      Else
      Sleep($time)
      start()
      EndIf
   Else
      Sleep($time)
   start()
   EndIf
   Else
   Sleep($time)
   start()
      EndIf
   Else
   Sleep($time)
   start()
   EndIf
  
  
EndFunc
Func WaitMouseMove()
      If $initial_positionx = MouseGetPos(0) Then
      If $initial_positiony = MouseGetPos(1) Then
      Sleep($time/2)
      WaitMouseMove()
      Else
      start()
      EndIf
   Else
      Sleep($time)
      start()
   EndIf
EndFunc

seems useless, but for those who live with someone who gets angry with the click noise at night is very good ;)

Link to comment
Share on other sites

you call start from itself over and over again and never come back to the main loop.

Also there are some conceptual issues.

Here is a solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Configurações", 250, 300, -1, -1)
$input_time = GUICtrlCreateInput("1", 150, 18, 80, 18)
$separador1 = GUICtrlCreateLabel("______________________________________________", 0, 0, 999, 15)
$abk1 = GUICtrlCreateLabel("Seconds waiting a move to verify (click or not):", 10, 19, 140)
$checkbox1 = GUICtrlCreateCheckbox(" Start", 10, 40, 120, 20)
$separador2 = GUICtrlCreateLabel("______________________________________________", 0, 60, 999)
$abk2 = GUICtrlCreateLabel("Close Window Explanation...", 10, 80, 220, 50)
$checkbox2 = GUICtrlCreateCheckbox(" Close the Window if mouse move to {X}", 10, 128, 200, 20)
$separador4 = GUICtrlCreateLabel("______________________________________________", 0, 150, 999)
$abk3 = GUICtrlCreateLabel("My OPTION2", 10, 170, 200, 32)
$checkbox2 = GUICtrlCreateCheckbox(" Active Shortcut of OPTION2 [Ctrl]", 10, 200, 200, 20)
$separador5 = GUICtrlCreateLabel("______________________________________________", 0, 220, 999)
$ok = GUICtrlCreateButton("Ok", 6, 240, 250 - 12, 54)
AutoItSetOption("TrayMenuMode", 1)
$pref = TrayCreateItem("Configurações")
$aboutitem = TrayCreateItem("Sobre")
$exit = TrayCreateItem("Sair")

Global $__Start = 0, $ti
Dim $save_pos[2] = [-1,-1]

While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0

        Case $msg = $aboutitem
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            MsgBox(64, "About:", "Coded by Washington C. Santos")
        Case $msg = $pref
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            GUISetState(@SW_SHOW)
        Case $msg = $exit
            Exit
    EndSelect

    $msg2 = GUIGetMsg()
    Switch $msg2
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ok
            GUISetState(@SW_HIDE)
            If BitAND(GUICtrlRead($checkbox1), $GUI_CHECKED) Then
                $ti = TimerInit()
                $__Start = 1
            Else
                $__Start = 0
            EndIf
    EndSwitch
    If $__Start Then start()

WEnd

Func start()

    If TimerDiff($ti) < GUICtrlRead($input_time)*1000 Then Return
    $ti = TimerInit()

    $t_pos = MouseGetPos()

    If $save_pos[0] = $t_pos[0] And $save_pos[1] = $t_pos[1] Then
        MouseClick("Left")
    EndIf

    $save_pos = $t_pos

EndFunc

Oh and you cant use $input_time directly, it only holds the control ID of the input field. You have to use GUICtrlRead to get the actual text.

Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

you call start from itself over and over again and never come back to the main loop.

Also there are some conceptual issues.

Here is a solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Configurações", 250, 300, -1, -1)
$input_time = GUICtrlCreateInput("1", 150, 18, 80, 18)
$separador1 = GUICtrlCreateLabel("______________________________________________", 0, 0, 999, 15)
$abk1 = GUICtrlCreateLabel("Seconds waiting a move to verify (click or not):", 10, 19, 140)
$checkbox1 = GUICtrlCreateCheckbox(" Start", 10, 40, 120, 20)
$separador2 = GUICtrlCreateLabel("______________________________________________", 0, 60, 999)
$abk2 = GUICtrlCreateLabel("Close Window Explanation...", 10, 80, 220, 50)
$checkbox2 = GUICtrlCreateCheckbox(" Close the Window if mouse move to {X}", 10, 128, 200, 20)
$separador4 = GUICtrlCreateLabel("______________________________________________", 0, 150, 999)
$abk3 = GUICtrlCreateLabel("My OPTION2", 10, 170, 200, 32)
$checkbox2 = GUICtrlCreateCheckbox(" Active Shortcut of OPTION2 [Ctrl]", 10, 200, 200, 20)
$separador5 = GUICtrlCreateLabel("______________________________________________", 0, 220, 999)
$ok = GUICtrlCreateButton("Ok", 6, 240, 250 - 12, 54)
AutoItSetOption("TrayMenuMode", 1)
$pref = TrayCreateItem("Configurações")
$aboutitem = TrayCreateItem("Sobre")
$exit = TrayCreateItem("Sair")

Global $__Start = 0, $ti
Dim $save_pos[2] = [-1,-1]

While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0

        Case $msg = $aboutitem
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            MsgBox(64, "About:", "Coded by Washington C. Santos")
        Case $msg = $pref
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            GUISetState(@SW_SHOW)
        Case $msg = $exit
            Exit
    EndSelect

    $msg2 = GUIGetMsg()
    Switch $msg2
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ok
            GUISetState(@SW_HIDE)
            If BitAND(GUICtrlRead($checkbox1), $GUI_CHECKED) Then
                $ti = TimerInit()
                $__Start = 1
            Else
                $__Start = 0
            EndIf
    EndSwitch
    If $__Start Then start()

WEnd

Func start()

    If TimerDiff($ti) < GUICtrlRead($input_time)*1000 Then Return
    $ti = TimerInit()

    $t_pos = MouseGetPos()

    If $save_pos[0] = $t_pos[0] And $save_pos[1] = $t_pos[1] Then
        MouseClick("Left")
    EndIf

    $save_pos = $t_pos

EndFunc

Oh and you cant use $input_time directly, it only holds the control ID of the input field. You have to use GUICtrlRead to get the actual text.

Thank you! I would never have thought of that, not even because I came to study "Dim" and "TimerDiff" really will still have a lot to learn.

You can be in helping to remake the "WaitMouseMove ()"? I need to put it in the script to click it once and stop until the mouse is moved again, otherwise it will be necessary to keep moving the mouse to click for him to stop ...

#EDIT

What's error in my new script? (i translate all label to my country language and add+ a start2 line, more don't run)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Configurações", 250, 300, -1, -1)
$input_time = GUICtrlCreateInput("1", 150, 18, 80, 18)
$separador1 = GUICtrlCreateLabel("______________________________________________", 0, 0, 999, 15)
$abk1 = GUICtrlCreateLabel("Segundos para Clicar:", 10, 19, 140)
$checkbox1 = GUICtrlCreateCheckbox(" Ligar", 10, 40, 120, 20)
$separador2 = GUICtrlCreateLabel("______________________________________________", 0, 60, 999)
$abk2 = GUICtrlCreateLabel("Fechar Janela: Fecha uma janela quando o mouse é levado ao canto da tela, evitando o clique duplo.", 10, 80, 220, 50)
$checkbox2 = GUICtrlCreateCheckbox(" Fechar janelas sem clicar no {X}", 10, 128, 200, 20)
$separador4 = GUICtrlCreateLabel("______________________________________________", 0, 150, 999)
$abk3 = GUICtrlCreateLabel("Arrastar: Segurar um item enquanto [Ctrl] estiver precionado.", 10, 170, 200, 32)
$checkbox2 = GUICtrlCreateCheckbox(" Ativar atalho [Ctrl] para arrastar", 10, 200, 200, 20)
$separador5 = GUICtrlCreateLabel("______________________________________________", 0, 220, 999)
$ok = GUICtrlCreateButton("Ok", 6, 240, 250 - 12, 54)
AutoItSetOption("TrayMenuMode", 1)
$pref = TrayCreateItem("Configurações")
$aboutitem = TrayCreateItem("Sobre")
$exit = TrayCreateItem("Sair")
Global $__Start = 0, $ti
Dim $save_pos[2] = [-1,-1]
While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0
        Case $msg = $aboutitem
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            MsgBox(64, "About:", "Coded by Washington C. Santos")
        Case $msg = $pref
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            GUISetState(@SW_SHOW)
        Case $msg = $exit
            Exit
    EndSelect
    $msg2 = GUIGetMsg()
    Switch $msg2
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ok
            GUISetState(@SW_HIDE)
            If BitAND(GUICtrlRead($checkbox1), $GUI_CHECKED) Then
                $ti = TimerInit()
                $__Start = 1
            Else
                $__Start = 0
            EndIf
    EndSwitch
    If $__Start Then start()
WEnd
Func start()
    If TimerDiff($ti) < GUICtrlRead($input_time)*1000 Then Return
    $ti = TimerInit()
    $t_pos = MouseGetPos()
    If $save_pos[0] = $t_pos[0] And $save_pos[1] = $t_pos[1] Then
        MouseClick("Left")
  start2()
    EndIf
    $save_pos = $t_pos
EndFunc
Func start2()
    If TimerDiff($ti) < GUICtrlRead($input_time)*1000 Then Return
    $ti = TimerInit()
    $t_pos = MouseGetPos()
    If $save_pos[0] = $t_pos[0] And $save_pos[1] = $t_pos[1] Then
        start2()
Else
  start()
    EndIf
    $save_pos = $t_pos
EndFunc
Edited by Washingtonhdmf
Link to comment
Share on other sites

Don't use Dim in any part of your script, it's not a good idea. Use Global if it's global, Local if it's local, and avoid Dim always. ReDim is perfectly fine, but not Dim.

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

@Washingtonhdmf

You think too complicated and you again do have a bad habit of calling the same function from itself, or two functions each other before they can finish. In this case you were lucky and you get back to the main loop eventually. But this kind of logic is very hard to follow.

Always remember to get back to the main loop as quick as possible. You dont want to block your gui, because you are stuck in a sub function or you are waiting for a sleep to finish.

- Try to work with global "switch" variables (like $__Start), not calling again the function you are in.

- Try to work with TimerInit/TimerDiff not sleep.

- If you want to call the same function again and again in a specific time frame you can also use AdlibRegister (look it up in the help file)

- Use "Tidy Autoit Source" from the Tools menu in Scite, it will make your code more readable.

Here is the script with a simple switch variable ($__Clicked) so the mouseclick will not be executed if the mouse haven't moved since the last click:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GUI = GUICreate("Configurações", 250, 300, -1, -1)
$input_time = GUICtrlCreateInput("1", 150, 18, 80, 18)
$separador1 = GUICtrlCreateLabel("______________________________________________", 0, 0, 999, 15)
$abk1 = GUICtrlCreateLabel("Seconds waiting a move to verify (click or not):", 10, 19, 140)
$checkbox1 = GUICtrlCreateCheckbox(" Start", 10, 40, 120, 20)
$separador2 = GUICtrlCreateLabel("______________________________________________", 0, 60, 999)
$abk2 = GUICtrlCreateLabel("Close Window Explanation...", 10, 80, 220, 50)
$checkbox2 = GUICtrlCreateCheckbox(" Close the Window if mouse move to {X}", 10, 128, 200, 20)
$separador4 = GUICtrlCreateLabel("______________________________________________", 0, 150, 999)
$abk3 = GUICtrlCreateLabel("My OPTION2", 10, 170, 200, 32)
$checkbox2 = GUICtrlCreateCheckbox(" Active Shortcut of OPTION2 [Ctrl]", 10, 200, 200, 20)
$separador5 = GUICtrlCreateLabel("______________________________________________", 0, 220, 999)
$ok = GUICtrlCreateButton("Ok", 6, 240, 250 - 12, 54)
AutoItSetOption("TrayMenuMode", 1)
$pref = TrayCreateItem("Configurações")
$aboutitem = TrayCreateItem("Sobre")
$exit = TrayCreateItem("Sair")

Global $__Start = 0, $__Clicked = 0, $ti
Global $save_pos[2] = [-1,-1]

While 1
    Local $msg = TrayGetMsg()
    Select
        Case $msg = 0

        Case $msg = $aboutitem
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            MsgBox(64, "About:", "Coded by Washington C. Santos")
        Case $msg = $pref
            TrayItemDelete($aboutitem)
            TrayItemDelete($exit)
            TrayItemDelete($pref)
            $pref = TrayCreateItem("Configurações")
            $aboutitem = TrayCreateItem("Sobre")
            $exit = TrayCreateItem("Sair")
            GUISetState(@SW_SHOW)
        Case $msg = $exit
            Exit
    EndSelect

    $msg2 = GUIGetMsg()
    Switch $msg2
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ok
            GUISetState(@SW_HIDE)
            If BitAND(GUICtrlRead($checkbox1), $GUI_CHECKED) Then
                $ti = TimerInit()
                $__Start = 1
            Else
                $__Start = 0
            EndIf
    EndSwitch
    If $__Start Then start()

WEnd

Func start()

    If TimerDiff($ti) < GUICtrlRead($input_time)*1000 Then Return
    $ti = TimerInit()

    $t_pos = MouseGetPos()

    If $save_pos[0] = $t_pos[0] And $save_pos[1] = $t_pos[1] Then
        If $__Clicked = 0 Then MouseClick("Left")
        $__Clicked = 1
    Else
        $__Clicked = 0
    EndIf

    $save_pos = $t_pos

EndFunc

Have Fun ;)

Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
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...