Hi guys,
I was wondering how I could create a script that would send a click wth coordinates that are relative to the current cursor position ? Is this possible ? Ie the cursor position value being zero , then have a hot key which is assigned to always click 30 pixels to the right of the current cursor position ? Sorry if I sound like a noob but I am ! I'm just learning with Auto IT and could really used the help on this
Send clicks relative to cursor position?
-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
- KuroiLight
- Posts: 328
- Joined: 12 Apr 2015, 20:24
- Contact:
Re: Send clicks relative to cursor position?
Code: Select all
MouseMove, 5, 5,, R
Click
Code: Select all
MouseGetPos, X, Y
MouseMove, 30, 0,, R
Click
MouseMove, %X%, %Y%,
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Thanks for the speedy reply I will try that out . Its ok , I meant to say AHK not AutoIt
Re: Send clicks relative to cursor position?
Click has a Relative optional parameter.
Example function:
Example function:
Code: Select all
1::RelativeClick(0,0,30,0)
RelativeClick(currX,currY,relX,relY)
{
MouseGetPos, pX, pY
if (pX = currX && pY = currY)
Click, %relX%, %relY%, Relative
}
Re: Send clicks relative to cursor position?
Thanks guys.... I cant seem to work out two other points now though lol . I want to bind scripts to the NumPad numbers, I tried this for NumPad 1 for example..
But that doesnt work. How do I format it ? And also, how do I declare left and up movement ?
Code: Select all
MouseGetPos, X, Y
MouseMove, 30, 0,, R
NumPad1::Click
MouseMove, %X%, %Y%,
Re: Send clicks relative to cursor position?
@Guest Have you run through the tutorial? Because you probably do not want code like that. If that is your only code in a script, it's going to move the mouse 30 pixels to the right as it's in the auto-execute section. And then you press Numpad1 to make a click wherever the mouse is. The second MouseMove is never executed because you have created a single-line hotkey.
-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Ok so I place the NumPad1 click at the end then ? I really need help with finalising this , the tutorial doesn't seem clear enough to me to get to the point I need to .
Last edited by fadetoblack on 21 Nov 2017, 21:35, edited 1 time in total.
- KuroiLight
- Posts: 328
- Joined: 12 Apr 2015, 20:24
- Contact:
Re: Send clicks relative to cursor position?
What are you trying to do with Numpad1?
the code I posted was merely to get you started you'll want to put that in a hotkey or function.
the code I posted was merely to get you started you'll want to put that in a hotkey or function.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Ok, basically I am trying to bind all Numpad numbers to scripts that all vary slightly in their click coordinates . So Numpad 1 script must click say 90 pixels up from the current cursor position, Numpad 2 must click 90 pixels up and 20 to the right , etc etc ....
- KuroiLight
- Posts: 328
- Joined: 12 Apr 2015, 20:24
- Contact:
Re: Send clicks relative to cursor position?
this might be what your looking for then:
Code: Select all
RelativeClick(rX := 0, rY := 0) {
MouseGetPos, X, Y
MouseMove, %rX%, %rY%,, R
Click
MouseMove, %X%, %Y%,
}
Numpad1::RelativeClick(0, -90)
Numpad2::RelativeClick(20, -90)
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Ok awesome thank you I will have a play around with that script ...
Re: Send clicks relative to cursor position?
To keep it simple by not using a function, but longer code, this is what you could do. I think it's easier to understand the long-form code and then seeing how it gets condensed with a function.
By using a function like KuroiLight does there, you assign values to variable defined in the function.
RelativeClick(rX := 0, rY := 0){ means the function name is RelativeClick (it can be almost any name you want), the first parameter is rX, and the second parameter is rY. You can use rX and rY as variables inside the function. The := 0 gives a default value to rX and rY -- that is, if you do not explicitly fill in that parameter when you call the function, it will use 0 there. Which means in KuroiLight's code, instead of Numpad1::RelativeClick(0, -90) (which calls the function; this is not the definition because the { is not there), you could actually use Numpad1::RelativeClick( , -90). The blank value for the first parameter would be treated as a 0 by the definition of the function.
And KuroiLight is using the variables rX and rY in the MouseMove command because that is what you are changing between the Numpad1 and Numpad2 hotkeys.
Code: Select all
Numpad1::
MouseGetPos, X, Y
MouseMove, 0, -90, , R
Click
MouseMove, %X%, %Y%
return
Numpad2::
MouseGetPos, X, Y
MouseMove, 20, -90, , R
Click
MouseMove, %X%, %Y%
return
RelativeClick(rX := 0, rY := 0){ means the function name is RelativeClick (it can be almost any name you want), the first parameter is rX, and the second parameter is rY. You can use rX and rY as variables inside the function. The := 0 gives a default value to rX and rY -- that is, if you do not explicitly fill in that parameter when you call the function, it will use 0 there. Which means in KuroiLight's code, instead of Numpad1::RelativeClick(0, -90) (which calls the function; this is not the definition because the { is not there), you could actually use Numpad1::RelativeClick( , -90). The blank value for the first parameter would be treated as a 0 by the definition of the function.
And KuroiLight is using the variables rX and rY in the MouseMove command because that is what you are changing between the Numpad1 and Numpad2 hotkeys.
- KuroiLight
- Posts: 328
- Joined: 12 Apr 2015, 20:24
- Contact:
Re: Send clicks relative to cursor position?
Thank you Exaskryz, I'm not too good at explaining things so I skip this sometimes and point to the docs.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Hi guys,
Thanks so much for your help , I have finalised it all now but I just wanted to ask one final thing . Would it be possible to have different "sets" of coordinates assgned to keys on the numberpad? Ideally i would prefer 3 different sets of numberpad keys coordinates and then have say down arrow for instance as a hotkey to toggle/cycle through them.. Is that possible ?
Thanks so much for your help , I have finalised it all now but I just wanted to ask one final thing . Would it be possible to have different "sets" of coordinates assgned to keys on the numberpad? Ideally i would prefer 3 different sets of numberpad keys coordinates and then have say down arrow for instance as a hotkey to toggle/cycle through them.. Is that possible ?
Re: Send clicks relative to cursor position?
Yes, that's possible. Assign your set changer hotkey to cycle through settings for a variable, then have a separate #If section of hotkeys for each variable setting. For example:
Code: Select all
KeySet := 1
Numpad9::
KeySet++
If KeySet > 3
KeySet := 1
return
#If KeySet = 1
Numpad1::RelativeClick(0, -90)
#If KeySet = 2
Numpad1::RelativeClick(20, -90)
#If KeySet = 3
Numpad1::RelativeClick(30, -90)
Last edited by Osprey on 22 Nov 2017, 17:45, edited 1 time in total.
-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Awesome, thanks for the reply . I will get on with that and see how it goes
Re: Send clicks relative to cursor position?
You're welcome. BTW, you can also consolidate the toggle hotkey into a single line, if you wish:
I'll leave the version above, though, since it may be easier for others to understand and modify.
Code: Select all
Numpad9::KeySet += KeySet < 3 ? 1 : -2 ; If KeySet is less than 3, add 1; otherwise, add -2 (i.e. subtract 2 from 3 to return to 1)
-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
OK thanks, upon mulling it over I think really I need to assign a key for each set rather than toggle. I want to use left arrow for keyset 1, down arrow for keyset 2 and right arrow for keyset 3. Could you possibly help me with that code ? How do I define that ?
Re: Send clicks relative to cursor position?
Code: Select all
^Numpad1::KeySet := 1
^Numpad2::KeySet := 2
^Numpad3::KeySet := 3
#If KeySet = 1
Numpad1::RelativeClick(0, -90)
#If KeySet = 2
Numpad1::RelativeClick(20, -90)
#If KeySet = 3
Numpad1::RelativeClick(30, -90)
-
- Posts: 14
- Joined: 01 Aug 2014, 20:04
Re: Send clicks relative to cursor position?
Its fine to use arrow keys for this , I know what you're saying but its fine in this case. I've run into a prob though, I'm getting Error: Call to nonexistent function Specifically : RelativeClick(40,-360) When I double click to execute.... Any ideas ? Complete code is below
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.
Left::KeySet := 1
Down::KeySet := 2
Right::KeySet := 3
#If KeySet = 1
Numpad1::RelativeClick(40, -360)
Numpad2::RelativeClick(160, -360)
Numpad3::RelativeClick(240, -300)
Numpad4::RelativeClick(0, -200)
Numpad5::RelativeClick(200, -200)
Numpad6::RelativeClick(350, -200)
Numpad7::RelativeClick(0, -60)
Numpad8::RelativeClick(200, -60)
Numpad9::RelativeClick(350, -60)
NumpadDiv::RelativeClick(350, -60)
NumpadMult::RelativeClick(350, -60)
NumpadSub::RelativeClick(350, -60)
NumpadPgUp::RelativeClick(350, -60)
NumpadPgDn::RelativeClick(350, -60)
NumpadHome::RelativeClick(350, -60)
NumpadEnd::RelativeClick(350, -60)
#If KeySet = 2
Numpad1::RelativeClick(40, -360)
Numpad2::RelativeClick(160, -360)
Numpad3::RelativeClick(240, -300)
Numpad4::RelativeClick(0, -200)
Numpad5::RelativeClick(200, -200)
Numpad6::RelativeClick(350, -200)
Numpad7::RelativeClick(0, -60)
Numpad8::RelativeClick(200, -60)
Numpad9::RelativeClick(350, -60)
#If KeySet = 3
Numpad1::RelativeClick(40, -360)
Numpad2::RelativeClick(240, -360)
Numpad3::RelativeClick(0, -200)
Numpad4::RelativeClick(240, -200)
Numpad5::RelativeClick(0, -100)
Numpad6::RelativeClick(240, -100)
Numpad7::RelativeClick(0, -60)
Numpad8::RelativeClick(350, -60)
Who is online
Users browsing this forum: chubbychub, Google [Bot] and 45 guests