Hi everyone. I have a question if this is possible. and I may need help on these.
I wanted to record an x/y location of the mouse pointer.
Example:
use case scenario. I hover a mouse position then press Ctrl + Numpad1 to record that mouse position to bind in Numpad1, Then hover again another location and press Ctrl + Numpad2 saves that mouse location in Numpad 2. when I press Numpad1 mouse move immediately to the recorded location and numpad2 and so on. by doing so consecutively I can have many mouse locator bound to the keys I want. Is this possible or can somebody help me code this?
Thank you so much.
Record a mouse position to a key
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Code: Select all
pos := {}
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
^Numpad1::
^Numpad2::
^Numpad3::
^Numpad4::
^Numpad5::
^Numpad6::
^Numpad7::
^Numpad8::
^Numpad9::
MouseGetPos, x, y
item := SubStr(A_ThisHotkey, 2), pos[item, 1] := x, pos[item, 2] := y
SoundBeep, 1500
Return
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Thank you so much. This is a great Help. I can't thank you enough.mikeyww wrote: ↑15 May 2021, 11:33Code: Select all
pos := {} Numpad1:: Numpad2:: Numpad3:: Numpad4:: Numpad5:: Numpad6:: Numpad7:: Numpad8:: Numpad9::MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2] ^Numpad1:: ^Numpad2:: ^Numpad3:: ^Numpad4:: ^Numpad5:: ^Numpad6:: ^Numpad7:: ^Numpad8:: ^Numpad9:: MouseGetPos, x, y item := SubStr(A_ThisHotkey, 2), pos[item, 1] := x, pos[item, 2] := y SoundBeep, 1500 Return
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Thank you so much.mikeyww wrote: ↑15 May 2021, 11:33Code: Select all
pos := {} Numpad1:: Numpad2:: Numpad3:: Numpad4:: Numpad5:: Numpad6:: Numpad7:: Numpad8:: Numpad9::MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2] ^Numpad1:: ^Numpad2:: ^Numpad3:: ^Numpad4:: ^Numpad5:: ^Numpad6:: ^Numpad7:: ^Numpad8:: ^Numpad9:: MouseGetPos, x, y item := SubStr(A_ThisHotkey, 2), pos[item, 1] := x, pos[item, 2] := y SoundBeep, 1500 Return
Re: Record a mouse position to a key
You are welcome. Have fun with it!
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Is it possible to add to the code while pressing the arrow left or right it will cycle through the selected numpad?
Re: Record a mouse position to a key
Code: Select all
pos := {}
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::move(pos, SubStr(A_ThisHotkey, 0))
^Numpad1::
^Numpad2::
^Numpad3::
^Numpad4::
^Numpad5::
^Numpad6::
^Numpad7::
^Numpad8::
^Numpad9::
MouseGetPos, x, y
item := SubStr(A_ThisHotkey, 0), pos[item, 1] := x, pos[item, 2] := y
SoundBeep, 1500
Return
Left::
Right::
If !item
Return
Loop
item := A_ThisHotkey = "Left" ? (--item ? item : 9) : (item++ - 9 ? item : 1)
Until (pos[item].1 > "")
move(pos, item)
Return
move(array, item) {
MouseMove, array[item].1, array[item].2
}
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Is the Arrow selector limits to 9 selection only?
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Say I wanted to add keys...
Code: Select all
pos := {}
F1::
F2::
F3::
F4::
F5::
F6::
F7::
F8::
F9::
F10::
F11::
F12::
Numpad0::
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::move(pos, SubStr(A_ThisHotkey, 0))
^F1::
^F2::
^F3::
^F4::
^F5::
^F6::
^F7::
^F8::
^F9::
^F10::
^F11::
^F12::
^Numpad0::
^Numpad1::
^Numpad2::
^Numpad3::
^Numpad4::
^Numpad5::
^Numpad6::
^Numpad7::
^Numpad8::
^Numpad9::
MouseGetPos, x, y
item := SubStr(A_ThisHotkey, 0), pos[item, 1] := x, pos[item, 2] := y
SoundBeep, 1500
Return
Left::
Right::
If !item
Return
Loop
item := A_ThisHotkey = "Left" ? (--item ? item : 9) : (item++ - 9 ? item : 1)
Until (pos[item].1 > "")
move(pos, item)
Return
move(array, item) {
MouseMove, array[item].1, array[item].2
}
Re: Record a mouse position to a key
I will leave this third round of changes to you. Perhaps you can see some patterns here in the script. The idea is that you have an array with elements that reflect each of the hotkeys. You store the mouse position in the array element that corresponds to the (Ctrl) hotkey that was pressed. You can then retrieve that position from the array when the non-Ctrl hotkey is pressed. You could use hotkey names for the element names. You could then have a separate master array that names the keys, so that the script could cycle through them as needed.
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Thank you so much.mikeyww wrote: ↑16 May 2021, 08:44I will leave this third round of changes to you. Perhaps you can see some patterns here in the script. The idea is that you have an array with elements that reflect each of the hotkeys. You store the mouse position in the array element that corresponds to the (Ctrl) hotkey that was pressed. You can then retrieve that position from the array when the non-Ctrl hotkey is pressed. You could use hotkey names for the element names. You could then have a separate master array that names the keys, so that the script could cycle through them as needed.
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Code: Select all
pos := {}
F1::
F2::
F3::
F4::
F5::
F6::
F7::
F8::
F9::
F10::
F11::
F12::
Numpad0::
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
^F1::
^F2::
^F3::
^F4::
^F5::
^F6::
^F7::
^F8::
^F9::
^F10::
^F11::
^F12::
^Numpad0::
^Numpad1::
^Numpad2::
^Numpad3::
^Numpad4::
^Numpad5::
^Numpad6::
^Numpad7::
^Numpad8::
^Numpad9::
MouseGetPos, x, y
item := SubStr(A_ThisHotkey, 2), pos[item, 1] := x, pos[item, 2] := y
SoundBeep, 1500
Return
Pressing CTRl (^) + key above will allow me to store into 9 key positions only. If I exceed 9 keys, the first Keybind will be override by the another keybind, Thus giving me only total of 9 Key positions. How can I save all the Key positions indicated more than 9 keys?
Thank you.
Re: Record a mouse position to a key
Code: Select all
pos := {}
*F1::
*F2::
*F3::
*F4::
*F5::
*F6::
*F7::
*F8::
*F9::
*F10::
*F11::
*F12::
*Numpad0::
*Numpad1::
*Numpad2::
*Numpad3::
*Numpad4::
*Numpad5::
*Numpad6::
*Numpad7::
*Numpad8::
*Numpad9::
If GetKeyState("Ctrl") {
MouseGetPos, x, y
pos[A_ThisHotkey, 1] := x, pos[A_ThisHotkey, 2] := y
SoundBeep, 1500
} Else MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
Return
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Thank you.
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Need Help.
Is it still possible to Add these lines to the Script above?
My intention is if I press Arrow Left / right I can tab or select and go to the next saved Mouse coordinate or back.
I can't seem to get it work.
Code: Select all
Global pos := {}, ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
OnExit("save")
IniRead, keyNames, %ini%
For each, key in StrSplit(keyNames, "`n") {
IniRead, section, %ini%, %key%
For each2, line in StrSplit(section, "`n")
part := StrSplit(line, "="), pos[key, part.1] := part.2
}
*F1::
*F2::
*F3::
*F4::
*F5::
*F6::
*F7::
*F8::
*F9::
*F10::
*F11::
*F12::
*Numpad0::
*Numpad1::
*Numpad2::
*Numpad3::
*Numpad4::
*Numpad5::
*Numpad6::
*Numpad7::
*Numpad8::
*Numpad9::
If GetKeyState("Ctrl") {
MouseGetPos, x, y
pos[A_ThisHotkey, 1] := x, pos[A_ThisHotkey, 2] := y
SoundBeep, 1500
} Else MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
Return
Is it still possible to Add these lines to the Script above?
Code: Select all
Left::
Right::
If !item
Return
Loop
item := A_ThisHotkey = "Left" ? (--item ? item : 9) : (item++ - 9 ? item : 1)
Until (pos[item].1 > "")
move(pos, item)
Return
move(array, item) {
MouseMove, array[item].1, array[item].2
}
I can't seem to get it work.
Re: Record a mouse position to a key
You may want to revert to a previous version. viewtopic.php?p=399979#p399979
This uses an array key corresponding to the digit of the keyboard key.
This uses an array key corresponding to the digit of the keyboard key.
-
- Posts: 63
- Joined: 05 May 2021, 10:19
Re: Record a mouse position to a key
Thanks Mike, but I wanted to save the Coordinate in a separate ini file... is this possible with the old script?
Re: Record a mouse position to a key
Below is an example that you can adjust.
Code: Select all
Global ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini"), pos := {}
IniRead, sectionList, %ini%
For each, digit in StrSplit(sectionList, "`n")
Loop, 2 {
IniRead, coord, %ini%, %digit%, %A_Index%
pos[digit, XY := A_Index] := coord
}
OnExit("save")
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::move(pos, SubStr(A_ThisHotkey, 0))
^Numpad1::
^Numpad2::
^Numpad3::
^Numpad4::
^Numpad5::
^Numpad6::
^Numpad7::
^Numpad8::
^Numpad9::
MouseGetPos, x, y
item := SubStr(A_ThisHotkey, 0), pos[item, 1] := x, pos[item, 2] := y
SoundBeep, 1500
Return
Left::
Right::
If !item
Return
Loop
item := A_ThisHotkey = "Left" ? (--item ? item : 9) : (item++ - 9 ? item : 1)
Until (pos[item].1 > "")
move(pos, item)
Return
move(array, item) {
MouseMove, array[item].1, array[item].2
}
save(exitReason, exitCode) {
For digit, set in pos
For xy, coord in set
IniWrite, %coord%, %ini%, %digit%, %xy%
}
Who is online
Users browsing this forum: Google [Bot] and 326 guests