Page 1 of 1

Hopelessly stuck

Posted: 18 Jun 2017, 18:03
by Zlysium
I'm trying to make a script that will, after the user left clicks, will move the cursor to a predetermined location on the screen, left click there, and then move back to the original position. and not just one time but every time with a toggle to turn it on/off i don't know how to do most of that but what i've got so far is:

f12::

~LButton::
MouseGetPos, StartX, StartY
Sleep 100
click 800, 600
MouseMove, StartX, StartY


return



which clearly isn't working as intending. all help much appreciated <3

the idea for the click to be in the active window and the cursor to return to wherever the original click came from. i think i got that part figured out at least :)

Re: Hopelessly stuck  Topic is solved

Posted: 18 Jun 2017, 18:13
by HotKeyIt
Try:

Code: [Select all] [Download] GeSHi © Codebox Plus

f12::Suspend, Toggle

LButton::
MouseGetPos, StartX, StartY
Sleep 100
click 800, 600
MouseMove, StartX, StartY
return

Re: Hopelessly stuck

Posted: 18 Jun 2017, 18:32
by Zlysium
It wasn't working, as is, after increasing the sleep to 300 and adding another sleep 100 after mousemove it functioned perfectly! No idea why honestly but hey it works! Now i wonder is there a way to make the entire script only function in the chosen application and not work elsewhere? like IfWinActive ? i'm not certain how it works honestly. If the IfWinActive is called then presumably the chosen window must be active for ANY part of the script to function right? including the toggle?

Re: Hopelessly stuck

Posted: 18 Jun 2017, 18:32
by Zlysium
It wasn't working, as is, after increasing the sleep to 300 and adding another sleep 100 after mousemove it functioned perfectly! No idea why honestly but hey it works! Now i wonder is there a way to make the entire script only function in the chosen application and not work elsewhere? like IfWinActive ? i'm not certain how it works honestly. If the IfWinActive is called then presumably the chosen window must be active for ANY part of the script to function right? including the toggle? And TYVM

Re: Hopelessly stuck

Posted: 18 Jun 2017, 18:37
by Zlysium
Sorry further testing finds a fault, the click that calls the getPOS doesn't go through i guess? It's like it gets intercepted or something, i left click, everything works after that such as the click at 800/800 and the mouse returns to the start position, but the click that starts it all doesn't actually do anything outside of the script!

Re: Hopelessly stuck

Posted: 18 Jun 2017, 18:46
by SirRFI
Using the following will make the hotkeys work only in given process window - insert it before the hotkey.

Code: [Select all] [Download] GeSHi © Codebox Plus

#if (WinActive("ahk_exe your_process.exe"))



On side note: coords may be refering to active window, see here: CoordMode https://autohotkey.com/docs/commands/CoordMode.htm

Re: Hopelessly stuck

Posted: 18 Jun 2017, 18:50
by Zlysium
I tried this to try and fix the original click not functioning as it's being used to get the position of the mouse
f12::Suspend, Toggle

LButton::
MouseGetPos, StartX, StartY
Click StartX, StartY
Sleep 200
click 958, 345
Sleep 200
MouseMove, StartX, StartY
return

and that doesn't work. Is there not a way to click at startx and y or am i just using the wrong command?

Re: Hopelessly stuck

Posted: 18 Jun 2017, 19:12
by Zlysium
After realizing i could just send 'click" since the mouse is already there. i tried that. but it doesn't work. it seems while the script is running left click doesn't function outside of calling the script itself to do its job. is there a way to have it do both? or does AHK intercepting it means it no longer gets to its intended destination?

Re: Hopelessly stuck

Posted: 18 Jun 2017, 19:25
by Zlysium
Now functioning fully after switching to using right click as the hotkey instead of left click, freeing up leftclick for normal use during.