Page 1 of 1

"Send" a "loop" that moves the mouse and clicks

Posted: 09 May 2024, 10:11
by Darkmaster006
Hello! I have been trying to automate some of the things I've got to do daily, especially those concerning the mouse, and I've been trying to make a function that does this:
1. I move the mouse (pointer) to a position.
2. Once I have it in the position I need, I would like to press a key (say, F2, for example).
3. Once that key is pressed, I would like a "function" to be executed; I'm not sure exactly if it would need to be a loop, since it only needs to be executed once, and then end; and then executed again when I press F2 again; but it does contain many actions inside.
4. When F2 is pressed, then, I would like, first, to have the mouse click once (right click); then, to have the mouse move, some number of pixels down, say, 7; then, some number of pixels right, say, 9.
5. Once the pointer moves to where it needs to, to have it click again, at that spot. Then the function would end.
6. If I press F2 again, to have the same thing happen. Maybe with F3, F4 I could modify the areas where it moves and the number of pixels, but that'd be more easy to do once I have it functioning, since it's just about modifying parameters.

Hope what I would like to do has been clear so far. Now, on to the code, what I've got so far:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SendMode Event
#UseHook

F2::
        Send, #function to move mouse X pixels down would go here
        sleep, 100 (maybe not necessary?)
        Send, #function to move mouse X pixels right would go here
        sleep, 100 (maybe not necessary?)
return

This is another code I used to use the numpad as a mouse; I was thinking of getting these functions to the one above, but I have no idea how.

numpadmousespeed := 10
NumpadEnd::MouseMove, -%numpadmousespeed%, %numpadmousespeed%, 0, R
NumpadDown::MouseMove, 0, %numpadmousespeed%, 0, R
NumpadPgDn::MouseMove, %numpadmousespeed%, %numpadmousespeed%, 0, R
NumpadLeft::MouseMove, -%numpadmousespeed%, 0, 0, R
NumpadRight::MouseMove, %numpadmousespeed%, 0, 0, R
NumpadHome::MouseMove, -%numpadmousespeed%, -%numpadmousespeed%, 0, R
NumpadUp::MouseMove, 0, -%numpadmousespeed%, 0, R
NumpadPgUp::MouseMove, %numpadmousespeed%, -%numpadmousespeed%, 0, R
NumpadDel::MouseClick
|::MouseClick
NumpadIns::MouseClick, Right
NumpadDel & NumpadSub::numpadmousespeed -= ((numpadmousespeed>5)*5*(!GetKeyState("Numlock", "T")))
NumpadDel & NumpadAdd::numpadmousespeed += ((numpadmousespeed<100)*5*(!GetKeyState("Numlock", "T")))

~< & Up::Send {WheelUp}
~< & Down::Send {WheelDown}
Any help is appreciated, thank you very much.

Re: "Send" a "loop" that moves the mouse and clicks

Posted: 09 May 2024, 10:38
by boiler
Just in terms of combining the scripts into one:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SendMode Event
#UseHook

numpadmousespeed := 10

F2::
        Send, #function to move mouse X pixels down would go here
        sleep, 100 (maybe not necessary?)
        Send, #function to move mouse X pixels right would go here
        sleep, 100 (maybe not necessary?)
return

NumpadEnd::MouseMove, -%numpadmousespeed%, %numpadmousespeed%, 0, R
NumpadDown::MouseMove, 0, %numpadmousespeed%, 0, R
NumpadPgDn::MouseMove, %numpadmousespeed%, %numpadmousespeed%, 0, R
NumpadLeft::MouseMove, -%numpadmousespeed%, 0, 0, R
NumpadRight::MouseMove, %numpadmousespeed%, 0, 0, R
NumpadHome::MouseMove, -%numpadmousespeed%, -%numpadmousespeed%, 0, R
NumpadUp::MouseMove, 0, -%numpadmousespeed%, 0, R
NumpadPgUp::MouseMove, %numpadmousespeed%, -%numpadmousespeed%, 0, R
NumpadDel::MouseClick
|::MouseClick
NumpadIns::MouseClick, Right
NumpadDel & NumpadSub::numpadmousespeed -= ((numpadmousespeed>5)*5*(!GetKeyState("Numlock", "T")))
NumpadDel & NumpadAdd::numpadmousespeed += ((numpadmousespeed<100)*5*(!GetKeyState("Numlock", "T")))

~< & Up::Send {WheelUp}
~< & Down::Send {WheelDown}

See Structure of a Script.