Hi. I'm fairly new to these kind of stuff (this forum and other stuff...), so I'm trying out stuff here and there, wondering why stuff don't work. The code I have posted here ended up like this due to testing different stuff... I'll try to explain the things I think I might have done if you like (I've done it anyway). Code below.
GOAL:
I want to make a script that clicks a button at a specific coordinate (preferably with the client's coordinates instead of the window) every 250 secs in the game window when it's running in the background, so I don't have to check up on it every time.
Also with a ToolTip box to display the elapsed time since automating this click thingy.
----
MAIN PROBLEM:
Performing the click on the specified coordinates doesn't work. Based on MouseGetPos, the coordinates to send the click to have changed to the relative coordinates of the current active window.
----
What I (presumably) did:
I set the timer to give feedback every 15 secs
Because of my experience with ControlSend and ahk_pid in the past, I decided to use ahk_id to send clicks via ControlClick instead of ahk_pid.
(Well... turns out it didn't work so ahk_pid it is! )
Having received no feedback at all with the manually specified coordinates for ControlClick to perform at the 'Scratch' label, I made a hotkey that did the same thing on demand but sticked to clicks at my cursor position. All while retrieving information I may need on cursor position with ToolTip (probably did that later on too for the 'Scratch' label click.
...
More tweaking after referencing Manual
ControlClick works when the game window is active, and also when it's inactive*, but somehow I want it differently.
*see MAIN PROBLEM
Other info:
WHND(control) reads blank for both ToolTip boxes.
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.
#Persistent
CoordMode, % "Mouse", % "Window"
CoordMode, % "ToolTip", % "Screen"
Target := "14952" ; insert ahk_pid, Window Spy
TargetControlSend := WinExist(Target) ; retrieve WHND from said window
SetTimer, % "Scratch", % "15000"
; SetTimer, % "ToolTip", % "1000"
Return
Scratch:
MouseGetPos, Xcraft, Ycraft, WinReal, WHNDreal, 2
ToolTip, % "
(
Current mouse position: "Xcraft "," Ycraft "
WHND: " WinReal "
WHND(control): " HWNDreal
), 200, 0, 2
SetControlDelay -1
ControlClick, X%Xcraft% Y%Ycraft%, % "ahk_pid " Target,,,, NA
Return
/*
; WIP
ToolTip:
ToolTip, % "
(Time
*/
; testing phase, comment out if script is rdy
^T::
MouseGetPos, Xtest, Ytest, WinTest, HWNDtest, 2
ToolTip, % "
(
Current mouse position: " Xtest "," Ytest "
WHND: " WinTest "
WHND(control): " HWNDtest
), 0, 0, 1
; Click, left, 2
SetControlDelay -1
ControlClick, x133 y222 , % "ahk_pid " Target,, LEFT, 1, NA
return
^r::Reload
:*:!exit::
ExitApp