Jump to content

Move mouse and click script


Recommended Posts

Hi

I used to be good in Autoit in old times but now I forgot everything and can't handle this.

I want to create script for my work, which will start different mousemoves + clicks  depending on which key was pressed from F5 to F10.

I know it is possible because I wrote many scripts like that in past.

Why is this not even running and is closed immediately after msgbox?

Please help.


 

HotKeySet("{ESC}" , "close")
HotKeySet("{F2}" , "pause")
HotKeySet("{F5}" , "Fax")


MsgBox (64, "Autokonsultant", "ESC = Zamknięcie. F2 = pauza. F5 = Fax.")


Func close()
    Exit
EndFunc

Func pause()
   If $click = False Then
      $click = True
      ToolTip("Autokonsultant chodzi" , 0 , 0)
   Else
      $click = False
      ToolTip("Autokonsultant zapauzowany" , 0 , 0)
   EndIf
EndFunc


Func Fax()
   MouseMove ( 25, 76 )
EndFunc

 

Link to comment
Share on other sites

Because you need to add statements telling the script to wait until one of the hotkeys was pressed.
Usually this is a While loop - insert after MsgBox:

While 1
    Sleep(100)
WEnd

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Sorry, I can't edit the post above... ;/

My pause element gives me an error. 

What's wrong with my pause?

Quote

 

HotKeySet("{ESC}" , "close")
HotKeySet("{F2}" , "pause")
HotKeySet("{F5}" , "Fax")


MsgBox (64, "Autokonsultant", "ESC = Zamknięcie. F2 = pauza. F5 = Fax.")

While 1
    Sleep(100)
WEnd

Func close()
    Exit
EndFunc

Func pause()
   If $click = False Then
      $click = True
      ToolTip("Autokonsultant chodzi" , 0 , 0)
   Else
      $click = False
      ToolTip("Autokonsultant zapauzowany" , 0 , 0)
   EndIf
EndFunc


Func Fax()
   MouseMove ( 25, 76 )
EndFunc

 

 

Link to comment
Share on other sites

„Gives me an error“ Which error?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

38 minutes ago, CzarnyKhaki said:

What's wrong with my pause?

HotKeySet("{ESC}", "close")
HotKeySet("{F2}", "pause")
HotKeySet("{F5}", "Fax")

Global $g_bClick = True

MsgBox(64, "Autokonsultant", "ESC = Zamkniecie. F2 = pauza. F5 = Fax.")

While 1
    Sleep(100)
WEnd

Func close()
    Exit
EndFunc   ;==>close

Func pause()
    If $g_bClick = False Then
        $g_bClick = True
        ToolTip("Autokonsultant chodzi", 0, 0)
        ConsoleWrite("Autokonsultant chodzi -> Running..." & @CRLF)
    Else
        $g_bClick = False
        ToolTip("Autokonsultant zapauzowany", 0, 0)
        ConsoleWrite("Autokonsultant zapauzowany -> Paused..." & @CRLF)
    EndIf
EndFunc   ;==>pause

Func Fax()
    MouseMove (25, 76 )
    ConsoleWrite('Fax() -> MouseMove (25, 76 )' & @CRLF)
EndFunc   ;==>Fax

Next time provide the error message !

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Well, the pause func should stay in the function when Pause is True.  Now the function is simply a toggle of a variable and a display of messages...

Edit Give meaningful name to variables is a good idea !

Edited by Nine
Link to comment
Share on other sites

3 hours ago, CzarnyKhaki said:

Error: Variable used without being declared

This has already been answered ;

5 hours ago, Danp2 said:

You haven't declared the $click variable anywhere in your script.

Please run the following script (Proszę przetestować następujący skrypt) :

HotKeySet("{ESC}", "_Exit")
HotKeySet("{F2}", "_TogglePause")
HotKeySet("{F5}", "_Fax")

Global $g_bPaused = False

MsgBox(64, "Autokonsultant", "ESC = Zamkniecie. F2 = pauza. F5 = Fax.")

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(100)
        ToolTip("Autokonsultant zapauzowany  -> Script Paused... ", 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>_TogglePause

Func _Fax()
    MouseMove (25, 76 )
    ConsoleWrite('Fax() -> MouseMove (25, 76 )' & @CRLF)
EndFunc   ;==>_Fax

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Great thanks for help. That worked. Can you help me with next problem? I'd wish to continue this thread. 
Can coordinates of mousemove or sent text be a bit random? I'd like to replace the

    MouseClickDrag ( "left", 462, 465, 409, 461, 2)   ; (2 is speed)
    Send("17:55")"

in the _Przelozenie function to choose random hour from 17:01 to 19:56 instead always 17:55 or to replace it with mouse move randomly from x=484 to x=533 with stable y=508, something like 

    MouseMove (randomXfrom484to533, 508)
    MouseClick ("left")

The full code is:

HotKeySet("{ESC}", "_Exit")
HotKeySet("{F1}", "_Przygotowanie")
HotKeySet("{F2}", "_Fax")
HotKeySet("{F3}", "_Pomylka")
HotKeySet("{F4}", "_Odmowa")
HotKeySet("{F5}", "_Niepracuje")
HotKeySet("{F6}", "_Przelozenie")
HotKeySet("{F12}", "_TogglePause")


Global $g_bPaused = False

MsgBox(64, "AUTOKONSULTANT ARTERIA", "Najpierw się zaloguj i wybierz kampanię. Następnie wciśnij F1.                Funkcje do zapamiętania (klawisze na klawiaturze):                                  ESC = Zamknięcie. F1 = Przygotowanie. F2 = Fax. F3 = Pomyłka. F4 = Odmowa rozmowy. F5 = Nie ma stałego źródła dochodu. F6 = Przełożenie rozmowy na 17:55. F12 = Pauza Autokonsultanta Arteria.")


While 1
    Sleep(4)
WEnd


Func _Exit()
    Exit
EndFunc   ;==>_Exit


Func _Przygotowanie()
    ToolTip("TRWA PRZYGOTOWANIE PROGRAMU", 0, 0)
    MouseClickDrag ( "left", 241, 240, 49, 15, 5)   ; (5 is speed)
    MouseClickDrag ( "left", 896, 531, 747, 980, 4) ; (4 is speed)
    MouseClickDrag ( "left", 739, 972, 745, 979, 2) ; (2 is speed)
    MouseMove (627, 44)
    ConsoleWrite('Fax() -> MouseMove (627, 44)' & @CRLF)
    MouseClick ("left")
    MouseMove (634, 570)
    MouseClick ("left")
    ToolTip("GOTOWE!", 658, 578)
    Sleep(1400)
    ToolTip("", 750, 990)
EndFunc   ;==>_Przygotowanie


Func _TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(4)
        ToolTip("AUTOKONSULTANT ARTERIA ZAPAUZOWANY. WCINIŚNIJ F2 ABY ODPAUZOWAĆ", 0, 0)
    WEnd
    ToolTip("", 0, 0)
EndFunc   ;==>_TogglePause


Func _Fax()
    ToolTip("FAX", 0, 0)
    MouseMove (25, 76)
    MouseClick ("left")
    MouseMove (179, 477)
    MouseClick ("left")
    MouseMove (229, 812)
    MouseClick ("left")
    ToolTip("", 750, 990)
EndFunc   ;==>_Fax


Func _Pomylka()
    ToolTip("POMYŁKA", 0, 0)
    MouseMove (25, 76)
    MouseClick ("left")
    MouseMove (180, 611)
    MouseClick ("left")
    MouseMove (229, 812)
    MouseClick ("left")
    ToolTip("", 750, 990)
EndFunc   ;==>_Pomylka


Func _Odmowa()
    ToolTip("ODMOWA ROZMOWY", 0, 0)
    MouseMove (25, 76)
    MouseClick ("left")
    MouseMove (179, 708)
    MouseClick ("left")
    MouseMove (226, 811)
    MouseClick ("left")
    ToolTip("", 750, 990)
EndFunc   ;==>_Odmowa


Func _Niepracuje()
    ToolTip("NIE MA STAŁEGO ŹRÓDŁA DOCHODU", 0, 0)
    MouseMove (168, 494)
    MouseClick ("left")
    MouseMove (241, 600)
    MouseClick ("left")
    MouseMove (175, 564)
    MouseClick ("left")
    MouseMove (215, 674)
    MouseClick ("left")
    MouseMove (177, 647)
    MouseClick ("left")
    MouseMove (243, 728)
    MouseClick ("left")
    MouseMove (175, 673)
    MouseClick ("left")
    MouseMove (240, 725)
    MouseClick ("left")
    MouseMove (198, 574)
    MouseClick ("left")
    MouseMove (265, 923)
    MouseClick ("left")
    MouseMove (197, 467)
    MouseClick ("left")
    MouseMove (223, 520)
    MouseClick ("left")
    MouseMove (173, 493)
    MouseClick ("left")
    MouseMove (206, 550)
    MouseClick ("left")
    ToolTip("", 750, 990)
EndFunc   ;==>_Niepracuje


Func _Przelozenie()
    ToolTip("PRZEŁOŻENIE ROZMOWY NA 17:55", 0, 0)
    MouseMove (98, 76)
    MouseClick ("left")
    MouseMove (296, 506)
    MouseClick ("left")
    MouseMove (226, 811)
    MouseClick ("left")
    MouseClickDrag ( "left", 462, 465, 409, 461, 2)   ; (2 is speed)
    Send("17:55")
    MouseMove (590, 871)
    MouseClick ("left")
    MouseMove (167, 809)
    MouseClick ("left")
    MouseMove (245, 867)
    MouseClick ("left")
    ToolTip("", 750, 990)
EndFunc   ;==>_Przelozenie
Edited by CzarnyKhaki
duplicate
Link to comment
Share on other sites

; mouse move randomly from x=484 to x=533 with stable y=508
Local $iRandomX ; $iRandomXfrom484to533 is not a good name for a variable :-)
$iRandomX = Random(484, 533, 1)

; choose random hour from 17:00 to 19:59 instead always 17:55
Local $sRandomTime
$sRandomTime = StringFormat("%02i:%02i", Random(17, 19, 1) , Random(0, 59, 1))

EDIT :

You should use english terms for function- and variable names. This makes it easier for other users to understand them ;).

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

11 minutes ago, CzarnyKhaki said:

Is it possible that the program read the date in format 2019-11-29 written as editeable text and add +1 day to it

Yes, but "how" will depends of the type of edit box you got, and what application underlies it.  Try first using Au3Info.exe tool to see if the control can be identified...

Link to comment
Share on other sites

In reading your script, you would be MUCH better off simply by hooking into the control. That way you don't need to worry about your mouse click being misplaced or worse, the wrong window is active and nothing works. 

Are you trying to automate Salesforce?

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