problem sending to a specific window

Ask gaming related questions (AHK v1.1 and older)
The_Kid_Thoor
Posts: 2
Joined: 03 Feb 2024, 19:29

problem sending to a specific window

Post by The_Kid_Thoor » 03 Feb 2024, 19:37

Hello friends and @Mikeyww. I'm having a problem sending the macro to a specific window. In the case of the window being the game Ragnarok, my macro never knows which Ragnarok window it will send the commands to.
I apologize in advance, I don't understand almost anything about programming. I will send what I write in the macro. If you could help me please.

Code: Select all

#If WinActive("ahk_class Ragnarok")

#MaxThreadsPerHotkey 2


$f7::

Toggle := !Toggle

While (Toggle) {

    ControlSend, ahk_parent, {f1 down}, ahk_class Ragnarok

    Sleep, 350

    ControlSend, ahk_parent, {f1 Up}, ahk_class Ragnarok

    Sleep, 450

    ControlSend, ahk_parent, {f1 down}, ahk_class Ragnarok

    Sleep, 350

    ControlSend, ahk_parent, {f1 Up}, ahk_class Ragnarok

    Sleep, 450

    ControlSend, ahk_parent, {f2 down}, ahk_class Ragnarok

    Sleep, 550

    ControlSend, ahk_parent, {f2 Up}, ahk_class Ragnarok

}

Return
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
Last edited by gregster on 03 Feb 2024, 19:40, edited 1 time in total.
Reason: Topic was split from a mostly unrelated topic.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: problem sending to a specific window

Post by mikeyww » 04 Feb 2024, 10:17

Welcome to this AutoHotkey forum!

Here are my suggestions for how to test ControlSend with a window.

1. Practice using ControlSend in Notepad, because Notepad responds to that command and will work. Use visible text in your testing.

2. Test a Send command first. Activate the window, and then use Send to send your text. Such testing requires no toggle, no loop, and no #If directives.

3. If #2 works, run a one-line test script that uses ControlSend to send your text. You can try without any control, with a named control, and with a parent. Send visible text so that you understand if it works.

Some programs require elevated scripts. Some programs block scripts. Some windows do not respond to ControlSend.

The_Kid_Thoor
Posts: 2
Joined: 03 Feb 2024, 19:29

Re: problem sending to a specific window

Post by The_Kid_Thoor » 06 Feb 2024, 18:12

Sorry, I think I wasn't clear. I have several windows open. Ragnarok 1 Ragnarok 2 Ragnarok 3. I want a macro for each specific window. I'll send an example when I saw @mikeyww you responding. I think it would be combining my script with what I'm going to send as an example.

Code: Select all

#Requires AutoHotkey v1.1.33
winTitle := "ahk_exe notepad.exe"
Global sel
Gui Font, s10
Gui Add, Text   , w350, Select window
Gui Add, ListBox, wp    vsel
Gui Add, Button , wp    Default, OK
Gosub F3

F3:: ; F3 = Show the GUI
WinGet win, List, % winTitle
If win {
 windows := ""
 Loop % win {
  WinGetTitle title, % "ahk_id" win%A_Index%
  windows .= "|" title
 }
 GuiControl, Enable, sel
 GuiControl,, sel, % windows
 GuiControl, Choose, sel, 1
 GuiControl, Enable, OK
} Else {
 SoundBeep 1500
 GuiControl,, sel, |
 GuiControl, Disable, sel
 GuiControl, Disable, OK
}
Gui, Show,, Send keys (F3 = show again)
Return

F7:: ; F7 = Stop sending keys
SetTimer go, Off
SoundBeep 1000
Return

buttonOK() {
 Gui Submit
 SetTimer go, 25
 SoundBeep 1500
}

GuiEscape() {
 Gui Hide
}

go() {
 ControlSend, Edit1, 123, % sel
}

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

User avatar
boiler
Posts: 17392
Joined: 21 Dec 2014, 02:44

Re: problem sending to a specific window

Post by boiler » 06 Feb 2024, 18:15

@The_Kid_Thoor - The moderators have been adding [code][/code] tags to your posts as noted at the bottom of each one. Please use them yourself when posting code on the forum. Thank you.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: problem sending to a specific window

Post by mikeyww » 06 Feb 2024, 18:26

If your goal is to ControlSend to the window with the same WinTitle as you have already defined on line 15, then you can do so within that loop. I do not know whether this is what you have in mind, because your goal is not clearly stated.

The script shows how to use WinGet and then loop through the HWND values that are retrieved. You can do this in your original script if needed there. Instead of a WinTitle with your window class, you will use ahk_id with the HWND value.

Post Reply

Return to “Gaming Help (v1)”