Jump to content

Loop Function variable times from Hotkeyset


Recommended Posts

Hello, i am new here. Tried many things, read already the "for..next help" but it was really short and couln't help me.
Here is what i want to do, simplified:

Hit Hotkey F11 for InputBox - Enter any Number -> this number will be the variable for looping the function
Hit Hotkey ESC for Function - the Function shall be looped according to the InputBox

now, my function will say: "Error: Variable used without being declared"
Script as I have it now is below. the Variable is exactly the same, but he cannot find it.

Func Input1()
Local $test = InputBox("Move Mouse", "Number of Loops: ", "", "", -1, 130) 
 

HotKeySet("{ESC}", "Move_mouse")
HotKeySet("{F11}", "Input1")
HotKeySet("{F1}", "STOP")                             ; Hit F1 in case of emergency :)



While 1
Sleep(10)
WEnd

Func Move_mouse()
For $i = 1 To  $test
MouseMove(25, 80, 5)                                                 
Sleep(50)
MouseMove(545, 190, 5)                                               
Next
EndFunc


while 1
    Sleep(50)
    WEnd
 

Func STOP()
    Exit 0
EndFunc

I hope you can understand what is wrong with this.. thanks for your help.

Edited by Melba23
Added code tags
Link to post
Share on other sites
  • Moderators

Samuel2021,

Welcome to the AutoIt forums.

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. Thanks in advance for your cooperation.

You need to declare $test as a Global variable so all functions can use it - I suggest reading the Variables - using Global, Local, Static and ByRef tutorial in the Wiki to get more details. You also do not terminate the initial Input1 function. Take a look at this modified script which I think does what you wish:

HotKeySet("{ESC}", "Move_mouse")
HotKeySet("{F11}", "Input1")
HotKeySet("{F1}", "STOP")                             ; Hit F1 in case of emergency :)

Global $test

While 1
    Sleep(10)
WEnd

Func Input1()
    $test = InputBox("Move Mouse", "Number of Loops: ", "", "", -1, 130)
EndFunc   ;==>Input1

Func Move_mouse()
    For $i = 1 To $test
        ConsoleWrite($test & " - MouseMove 1" & @CRLF)
        ;MouseMove(25, 80, 5)
        Sleep(50)
        ConsoleWrite($test & " - MouseMove 2" & @CRLF)
        ;MouseMove(545, 190, 5)
    Next
EndFunc   ;==>Move_mouse

Func STOP()
    Exit 0
EndFunc   ;==>STOP

Please ask if you have any questions.

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 post
Share on other sites
  • 3 months later...

Hello M23,

thank you,  I check out the Code tagging! 

Sorry I did not have notifications on to see your reply. 

For the Moment, i just did a loop of 300 but the script will unnecessarely do it's thing and maybe cause damage. 

Your suggestions makes great sense, will let you know once I got it worked! 

Thanks have a nice day!

Samuel

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...