Hey everyone.
I'm trying to make this script only send keys to the specific window, in this case it would be World of Warcraft.
Let's say you are currently in Notepad, and you press F2, it should only target World of Warcraft than anything else. So no matter in what program you are, it's always World of Warcraft, nothing else.
Could someone help me with that? That would be nice!
Here is my script:
banana:=0
; #Warn ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoEnv
ListLines Off
SendMode Input
list =
(
he3
pord
)
; FileRead, list, % pathToTheFile ; <<<< in order to load the list from a file instead
obj := StrSplit(list, "`n") ; generates an array of words from the linefeed separated list of word
l:= obj.length() ; store its length in a variable
#MaxThreadsPerHotkey, 2
F2::
banana:=!banana
while (banana=1)
{
Send {Enter}
DllCall("Sleep","UInt",170)
r++
SendInput % obj[r]
If (r=l)
{
r:=0 ; we'll make it r++ the next time you turn on this loop
banana:=0 ; this will break the while loop
}
sleep, DllCall("Sleep","UInt",340)
Send, {Enter}
DllCall("Sleep","UInt",1)
Send, w
}
return
F4:: ; press control+r to reload
Reload
Send keys (functions) to specific window
- eventhorizon
- Posts: 158
- Joined: 27 Oct 2016, 14:22
Re: Send keys (functions) to specific window
So my first question is. What keys do you want to send to the active window and what keys get sent to World of warcraft? Question two is what do you want to do if the window you're in uses the same key you want to send to WoW? like if you're typing something in Notepad and you want to send that same letter to WoW do you want to send it just to wow, just to the notepad, or to both? So many questions, so little time. And finally, why are you in a different window than the game you're playing in the first place? So how did you figure that the script would know if you want to send the key to one window or the other? Or lets say you're looking at the wow wiki and something happens in WoW that needs your attention -- like you get attacked and need to respond? how did you plan on handling that?
A computer lets you make more mistakes faster than any invention in human history – with the possible exceptions of handguns and tequila.
Re: Send keys (functions) to specific window
As you can see, the script picks up something from the list randomly if you hold F2 then sends it into the chat. I just want the script to be sending it to WoW instead of anything else, so, as for example, you're in a other program like Notepad, and you pressed F2, it should be sending to the window specified, since my WoW window is always running in background.eventhorizon wrote:So my first question is. What keys do you want to send to the active window and what keys get sent to World of warcraft? Question two is what do you want to do if the window you're in uses the same key you want to send to WoW? like if you're typing something in Notepad and you want to send that same letter to WoW do you want to send it just to wow, just to the notepad, or to both? So many questions, so little time. And finally, why are you in a different window than the game you're playing in the first place? So how did you figure that the script would know if you want to send the key to one window or the other? Or lets say you're looking at the wow wiki and something happens in WoW that needs your attention -- like you get attacked and need to respond? how did you plan on handling that?
Re: Send keys (functions) to specific window
Each of your Send/Input lines should be replaced with ControlSend.
ControlSend, ????, % obj[r], World of Warcraft
Of course change % obj[r] to {Enter} and w in their respective lines. The ??? is the trickiest part. Use window spy to find a control value. Window Spy can be accessed by right-clicking the tray icon (by the system clock) of a running script. I expect there will be none, but worth a shot. (You may actually need multiple control values -- one for the game client, then one for the chat box, if that is how WoW is constructed.) If you can't get any value to appear next to the "ClassNN:" in window spy, then I would try two things for the ??? (Blank) and ahk_parent.
The base line syntax for you would be:ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSend, ????, % obj[r], World of Warcraft
Of course change % obj[r] to {Enter} and w in their respective lines. The ??? is the trickiest part. Use window spy to find a control value. Window Spy can be accessed by right-clicking the tray icon (by the system clock) of a running script. I expect there will be none, but worth a shot. (You may actually need multiple control values -- one for the game client, then one for the chat box, if that is how WoW is constructed.) If you can't get any value to appear next to the "ClassNN:" in window spy, then I would try two things for the ??? (Blank) and ahk_parent.
Re: Send keys (functions) to specific window
Exaskryz wrote:Each of your Send/Input lines should be replaced with ControlSend.
The base line syntax for you would be:ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSend, ????, % obj[r], World of Warcraft
Of course change % obj[r] to {Enter} and w in their respective lines. The ??? is the trickiest part. Use window spy to find a control value. Window Spy can be accessed by right-clicking the tray icon (by the system clock) of a running script. I expect there will be none, but worth a shot. (You may actually need multiple control values -- one for the game client, then one for the chat box, if that is how WoW is constructed.) If you can't get any value to appear next to the "ClassNN:" in window spy, then I would try two things for the ??? (Blank) and ahk_parent.
Thanks for your information. I think I need a little further help as my script is not working. I changed it and it now looks like this:
banana:=0
; #Warn ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
WinGet, wowid, list, WORLD OF WARCRAFT
#IfWinActive, WORLD OF WARCRAFT
list =
(
yw
ywddy
32323
)
; FileRead, list, % pathToTheFile ; <<<< in order to load the list from a file instead
obj := StrSplit(list, "`n") ; generates an array of words from the linefeed separated list of word
l:= obj.length() ; store its length in a variable
#MaxThreadsPerHotkey, 2
F2::
banana:=!banana
while (banana=1)
{
ControlSend, ahk_id, {Enter}, WORLD OF WARCRAFT
DllCall("Sleep","UInt",170)
r++
ControlSend % obj[r]
If (r=l)
{
r:=0 ; we'll make it r++ the next time you turn on this loop
banana:=0 ; this will break the while loop
}
ControlSend, ahk_id, {Enter}
sleep, DllCall("Sleep","UInt",340)
ControlSend, ahk_id, {w}
DllCall("Sleep","UInt",1)
}
return
F4:: ; press control+r to reload
Reload
Have I done something wrong?
Re: Send keys (functions) to specific window
Change the ControlSend, ahk_id to ControlSend, ahk_parent or leave it blank. I wouldn't expect ahk_id to be a value that works for a Control parameter.
But beyond those two choices, I don't know what you'd need. You'd probably have to find what other people have used in trying to use ControlSend (or ControlClick) in World of Warcraft.
But beyond those two choices, I don't know what you'd need. You'd probably have to find what other people have used in trying to use ControlSend (or ControlClick) in World of Warcraft.
Re: Send keys (functions) to specific window
Exaskryz wrote:Change the ControlSend, ahk_id to ControlSend, ahk_parent or leave it blank. I wouldn't expect ahk_id to be a value that works for a Control parameter.
But beyond those two choices, I don't know what you'd need. You'd probably have to find what other people have used in trying to use ControlSend (or ControlClick) in World of Warcraft.
Yoah. I'll just keep googling.
Thanks anyways!
Who is online
Users browsing this forum: No registered users and 38 guests