Jump to content

Simple Looping Mouseclick


Recommended Posts

Hi all,

I have been trying to get a simple looping mouseclick script to work depending on the quantity you put into a popup box. I would also like the escape key to be a fallback to exit the loop as well as the count. I am getting errors when trying to run the .exe once compiled.

AutoIt Error
Line 4 (File "...\gomouse.exe):
Error: Unknown function name.

Here is the file


$Main = GUICreate("Enter Desired Clicks", 100, 100, 810, 200)
$Input1 = GUICtrlCreateInput("0", 40, 40, 33, 21)
$Go = GUICtrlCreateButton("Go", 40, 64, 33, 17, 0)
GUISetState(SW_SHOWNORMAL)

HotKeySet("F1", "_Mouse1")
HotKeySet("{ESC}", "_Escape")

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Go
         _Mouse1()
   EndSwitch
WEnd

Func _Mouse1()
   Local $Times
   Do
      $Times += 1
      MouseClick("left")
      Sleep(1000)
   Until $Times = GUICtrlRead($Input1) Or $Escape = 1
EndFunc

Func _Escape()
   $Escape = 1
EndFunc

Link to comment
Share on other sites

Welcome to AutoIt and the forum!
Is this script for learning purpose or do you want to solve a real problem? As you do not specify a mouse position it clicks whereever the mouse is at the moment you run your script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Your error is caused by the missing @ in @SW_SHOWNORMAL.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok, caught a couple mistakes but I still can't seem to get it completed. Once compiled now it does not stop the mouse click loop if it reached the number entered in the GUI box, it also does not exit if I press the window close button however pressing escape closes the window and program. Not sure what I am still missing to finish this script. Any help is appreciated!

#include <GUIConstantsEx.au3>

$Main = GUICreate("Enter Desired Clicks", 100, 100, 810, 200)
$Input1 = GUICtrlCreateInput("0", 40, 40, 33, 21)
$Go = GUICtrlCreateButton("Go", 40, 64, 33, 17, 0)
GUISetState()
Local $Times = 0
Local $Escape = 0
HotKeySet("F1", "_Mouse1")
HotKeySet("{ESC}", "_Escape")

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Go
         _Mouse1()
   EndSwitch
WEnd

Func _Escape()
   $Escape = 1
EndFunc

Func _Mouse1()
   Do
      $Times += 1
      MouseClick("left")
      Sleep(1000)
   Until $Times = GUICtrlRead($Input1) Or $Escape = 1
EndFunc

Link to comment
Share on other sites

Could you please anwer my question in my first post?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

It works one time as you do not reset $Escape=0 when you have hit ESC, so the second time it will Escape right away.

This however doesn't close your script but returns to its GUI.

Jos

 

 

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

BTW: Could you please enclose AutoIt code in code tags (the "<>" icon in the editor)? That greatly enhances readability ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Clicking the close button will not work while the script is in the loop inside _Mouse1(), as you are not polling GUIGetMsg there. The message will get registered as soon as you leave the loop. I don't know if you meant it like that.
  • Like Jos said, reset your $Escape, otherwise all runs after the first will only have exactly 1 loop iteration.
  • Even then, $Times is a global variable and just keeps on counting upwards. So if you reset $Escape, the script will stay in the loop forever after the first run. Meaning: also reset your $Times counter before you enter that loop.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

I can't imagine where such a script could be useful :huh: Clicking n times with a break of 1 second. Why wouldn't the user click himself?
Is this for a game?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I can't imagine where such a script could be useful :huh: Clicking n times with a break of 1 second. Why wouldn't the user click himself?
Is this for a game?

​Yes, needing to open a specific amount of items prior to running out, if it runs out then you start to purchase.

Link to comment
Share on other sites

  • Moderators

PlasticJesus,

Welcome to the AutoIt forum.

Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked.

See you soon with a legitimate question I hope.

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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