Run script on a specific window game only

Ask gaming related questions (AHK v1.1 and older)
Brillian
Posts: 17
Joined: 06 Nov 2017, 11:45

Run script on a specific window game only

06 Nov 2017, 12:58

Hello everyone! Is there any way that a script will run on a specific window only? Because I want to do some other stuff while running the script. I am playing an online game and I just need to spam keys: 1234567890 infinitely or until I press something that suspends the script.

I'm currently using these codes that I made last year:
if not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}

#Persistent
SetTimer, PressTheKey, 500
SetKeyDelay, 100
Return

PressTheKey:
SendEvent, 1234567890
Return

#If, A_IsPaused
Home::
Suspend
Pause
Return
#If
Home::
Suspend
Pause
Return
I have read that what I want is possible by using the ControlSend but I have no success of doing it.

Here is the thread that I saw awhile ago that makes a script run on a specific window:
https://autohotkey.com/board/topic/7183 ... ackground/

Can somebody help me, please? Thank you so much!
Brillian
Posts: 17
Joined: 06 Nov 2017, 11:45

Re: Run script on a specific window game only

07 Nov 2017, 02:16

Bump. Help please.
Brillian
Posts: 17
Joined: 06 Nov 2017, 11:45

Re: Run script on a specific window game only

07 Nov 2017, 08:12

Anyone can help me with this?
Brillian
Posts: 17
Joined: 06 Nov 2017, 11:45

Re: Run script on a specific window game only

17 Nov 2017, 15:00

BUMP..

Can't make it work. I want something like this: https://autohotkey.com/board/topic/7183 ... ackground/

Here is the info of the window I want to be affected by the AHK:
Window Title: Rohan
Class: ahk_class Rohan
Process: ahk_exe rohanclient.exe
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Run script on a specific window game only

17 Nov 2017, 15:54

Your hotkeys can be made to only work on the window if it's active by using #IfWinActive Rohan above the first hotkey you want to be affected (so, just put it at the top of the script).

Your timers you may want to make the first two lines under the label be this:

Code: Select all

IfWinNotActive, Rohan
   return
Which makes the timer do nothing if Rohan isn't the active window.
Brillian
Posts: 17
Joined: 06 Nov 2017, 11:45

Re: Run script on a specific window game only

23 Nov 2017, 09:53

Exaskryz wrote:Your hotkeys can be made to only work on the window if it's active by using #IfWinActive Rohan above the first hotkey you want to be affected (so, just put it at the top of the script).

Your timers you may want to make the first two lines under the label be this:

Code: Select all

IfWinNotActive, Rohan
   return
Which makes the timer do nothing if Rohan isn't the active window.
Thank you for the response, sir. I have a question. Disregarding my codes above. How can I make a new one to have a similar that can work on a selected window? Because I want to do stuffs simultaneously. With the codes I'm currently using, I cannot switch windows (alt tab) to do other works while my game is still pressing the hotkeys.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Run script on a specific window game only

24 Nov 2017, 22:23

You would need to change to #IfWinExist and IfWinNotExist as alternatives to the Active counterparts.

You would also need to use ControlSend / ControlClick to target the game. ControlSend / ControlClick are more complex commands than their normal Send/Click counterparts, so read the documentation closely.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: jameswrightesq and 125 guests