Reputation: 4432
I have the following ahk script to run C&C Generals:
#SingleInstance ignore
CoordMode, Mouse, Relative
Run C:\Users\william\Desktop\Generals.lnk
a::Left
s::Down
d::Right
w::Up
Loop{
sleep, 500
}
Until WinExist("ahk_exe Generals.exe")
sleep, 200
SetControlDelay -1
ControlClick, 1, ahk_class #32770, "", LEFT, 10, 300, 300
Loop{
sleep, 500
}
Until WinExist("ahk_exe Generals.exe")
WinWaitClose
Exit
The problem is that I can't get the ControlClick to click the second button.
I've read the manual but I can't figure out why this is not working. I don't even know if it clicks at all.
Got it working:
#SingleInstance ignore
CoordMode, Mouse, Relative
Run C:\Users\william\Desktop\Generals.lnk
winWait, ahk_exe Generals.exe
Click 300, 300
winWait, ahk_exe Generals.exe
WinWaitClose
Exit
a::Left
s::Down
d::Right
w::Up
Upvotes: 1
Views: 2471
Reputation: 10892
too much to comment on, I'll make it an answer instead:
a::Left
s::Down
d::Right
w::Up
Loop{
...
Key remappings (s::Down
) bring a return
with them implicitly. Same way as a hotkey like s::msgbox, hi
is only the short form for
s::
msgbox, hi
return
, key remappings are only a short form for multiple lines. So, your script terminates already after the Run
command. Put all your hotkeys, labels, functions, hotstrings and key remappings after everything you want to happen on program start. You can see your script behaviour if you double click the task bar icon. For more info, see the auto-execute section.
loop
sleep, 500
Until WinExist("ahk_exe Generals.exe")
there is actually a special command for this in AutoHotkey:
winWait, ahk_exe Generals.exe
ControlClick, 1, ahk_class #32770, "", LEFT, 10, 300, 300
controlClick is useful if you want to click into a window which is not in foreground. According to your image, C&C is pretty much in your foreground. So I guess you could simply use the click command.
Also (see controlClick explanation) the 1
as control-or-pos does not make any sense.. and what do you mean by 300, 300
? These are the options and excludeTitle parameters
WinWaitClose
do you intend to exit the game with your script? if not, this line makes no sense
Exit
if you want to keep your script running (for using the key remappings), exit is okay but return
would be more appropriate. If you want to exit the whole script, use exitapp
instead
The problem is that I can't get the ControlClick to click the second button.
what button??
Upvotes: 3