Run Script Only In One Window Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Javalotl
Posts: 5
Joined: 11 May 2021, 11:51

Run Script Only In One Window

11 May 2021, 12:00

I know this has been asked multiple times but I'm still having trouble understanding, I want to make a simple script that enters keys to a window in the background so I can have the script running and continue using my computer with it running. Below is an example of the script I have.

Code: Select all

/::
#Persistent
SetTimer, PressTheKey, 14000
return

PressTheKey:
Send, {f}
Sleep 500
Send, {f}
Sleep 1500
Send, {w down}
Sleep 1500
Send, {w up}
Send, c4
Sleep 1500
Send, {a down}
Sleep 1500
Send, {a up}
Sleep 1500
Send, {s down}
Sleep 1500
Send, {s up}
Sleep 1500
Send, {d down}
Sleep 1500
Send, {d up}
Sleep 1500
Send, x8
Send, cc2
Sleep 1500
return

.::Pause
User avatar
Javalotl
Posts: 5
Joined: 11 May 2021, 11:51

Re: Run Script Only In One Window

11 May 2021, 15:24

boiler wrote:
11 May 2021, 13:38
See ControlSend.
Can you give an example? I don't fully understand what goes where.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Run Script Only In One Window

11 May 2021, 16:10

Here’s an example that would send text to a Notepad window if you have one open when you run the script:

Code: Select all

ControlSend, Edit1, hello there, ahk_exe notepad.exe
User avatar
Javalotl
Posts: 5
Joined: 11 May 2021, 11:51

Re: Run Script Only In One Window

11 May 2021, 18:52

boiler wrote:
11 May 2021, 16:10
Here’s an example that would send text to a Notepad window if you have one open when you run the script:

Code: Select all

ControlSend, Edit1, hello there, ahk_exe notepad.exe
I still don't quite understand, how would I write that for my script in the original post?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Run Script Only In One Window  Topic is solved

11 May 2021, 19:42

I can't tell you exactly how since you haven't shared any details of your program's window or its control if you need to send it directly to a particular control. Use the Window Spy tool that came with AHK, and read about WinTitle and ControlSend.
User avatar
Javalotl
Posts: 5
Joined: 11 May 2021, 11:51

Re: Run Script Only In One Window

11 May 2021, 20:29

boiler wrote:
11 May 2021, 19:42
I can't tell you exactly how since you haven't shared any details of your program's window or its control if you need to send it directly to a particular control. Use the Window Spy tool that came with AHK, and read about WinTitle and ControlSend.
Window Spy is giving me:
"MORDHAU
ahk_class UnrealWindow
ahk_exe Mordhau-Win64-Shipping.exe
ahk_pid 8872"
So how would you write it to send inputs to that window? (ie Send, {f})
User avatar
Javalotl
Posts: 5
Joined: 11 May 2021, 11:51

Re: Run Script Only In One Window

11 May 2021, 21:18

boiler wrote:
11 May 2021, 19:42
I can't tell you exactly how since you haven't shared any details of your program's window or its control if you need to send it directly to a particular control. Use the Window Spy tool that came with AHK, and read about WinTitle and ControlSend.
Alright, I got it to work, thank you.

Code: Select all

SetTitleMatchMode 2

/::
#Persistent
SetTimer, PressTheKey, 14000
return

PressTheKey:
ControlSend, ahk_parent, f, MORDHAU
Sleep 500
ControlSend, ahk_parent, f, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {w down}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {w up}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {a down}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {a up}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {s down}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {s up}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {d down}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, {d up}, MORDHAU
Sleep 1500
ControlSend, ahk_parent, x8, MORDHAU
ControlSend, ahk_parent, cc2, MORDHAU
Sleep 1500
return

.::Pause

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], Joey5, mikeyww, RandomBoy, wpulford and 386 guests