 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Carnifex
Joined: 10 Nov 2009 Posts: 11
|
Posted: Tue Nov 10, 2009 3:24 am Post subject: ControlSend using Subroutines |
|
|
I am writing an automation script for a game I play a lot, but I am in desperate need of some help with the ControlSend command using Subroutines in relation to Hwnds.
In the following piece of code (note this is only a small part of the script), I use the ControlSend command to send messages to the game after reading coordinates from a certain file:
| Code: |
runNode:
ControlGet, handle, Hwnd,,, WinTitle ;I wrote WinTitle on purpose
Loop, read, %CoordFile%
{
%direction% = 1
if A_LoopReadLine = 1,0,0,0
{
ControlSend,, A_wSend, ahk_id %handle%
Sleep %timeDelay%
}
else if A_LoopReadLine = EndPath
{
Break
}
else
{
Msgbox, An Error has occured!
}
}
Return
;-----------------------------------------------------------------------------------------------------------------
wSend:
Send {up down}
Sleep 1000
Send {up up}
;-----------------------------------------------------------------------------------------------------------------
|
Now, here is the issue:
Whenever I write the following it all works perfectly fine: ( the only thing different is the Send x instead of Send {up down} and {up up} )
| Code: |
runNode:
ControlGet, handle, Hwnd,,, WinTitle ;I wrote WinTitle on purpose
Loop, read, %CoordFile%
{
%direction% = 1
if A_LoopReadLine = 1,0,0,0
{
ControlSend,, A_wSend, ahk_id %handle%
Sleep %timeDelay%
}
else if A_LoopReadLine = EndPath
{
Break
}
else
{
Msgbox, An Error has occured!
}
}
Return
;-----------------------------------------------------------------------------------------------------------------
wSend:
Send x
Sleep 1000
Send x
;-----------------------------------------------------------------------------------------------------------------
|
But when using the arrow keys (yes, I have tested it using a normal Send command to make sure the keystrokes work in-game) it just does nothing at all.
Can someone explain to me how this is any different ? Or is there something else going on here ? |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Nov 10, 2009 3:45 am Post subject: |
|
|
what about:
| Code: | wSend:
Send {up}
Sleep 1000
Send {up}
return |
and what about:
| Code: | wSend:
Send {x down}
Sleep 1000
Send {x up}
return |
|
|
| Back to top |
|
 |
amazed Guest
|
Posted: Tue Nov 10, 2009 7:22 am Post subject: |
|
|
I think you have (many) more problems than you think.
What do you expect this line to do?
| Code: | | ControlSend,, A_wSend, ahk_id %handle% |
What it will do is send the literal string "A_wSend". It in no way references the subroutine "wSend", and there is no way to make it do so.
Also your subroutine "A_wSend" is lacking a required "Return" statement and should look like this:
| Code: | wSend:
Send {up down} ; or Send x for you 2nd example
Sleep 1000
Send {up up} ; or Send x for you 2nd example
Return |
|
|
| Back to top |
|
 |
Kasper Guest
|
Posted: Tue Nov 10, 2009 8:39 am Post subject: |
|
|
| amazed wrote: |
What it will do is send the literal string "A_wSend". It in no way references the subroutine "wSend", and there is no way to make it do so. |
So then just out of curiosity, how would you use a "push key down" ({up down}) in a ControlSend? I just tested the following:
| Code: | | ControlSend,, {up down}, ahk_id %handle% |
It doesn't work~ |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Nov 10, 2009 8:42 am Post subject: |
|
|
| u can use for controlsend |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Nov 10, 2009 8:43 am Post subject: |
|
|
o wait, help file did mention an example
| Quote: | | ControlSend, Edit1, {Alt down}f{Alt up}, Untitled - Notepad |
|
|
| Back to top |
|
 |
Kasper Guest
|
Posted: Tue Nov 10, 2009 9:18 am Post subject: |
|
|
| Anonymous wrote: | | u can use for controlsend |
Can you show the full syntax for that? I've tried figuring out a way to do SetKeyDelay with ControlSends and the following does absolutely nothing (In fact, it just breaks the ControlSend even further):
| Code: | ControlSend,, a, ahk_id %handle%
SetKeyDelay, -1, 5000 |
|
|
| Back to top |
|
 |
Guest
|
Posted: Tue Nov 10, 2009 9:23 am Post subject: |
|
|
tested works for me on notepad
| Code: | SetTitleMatchMode, 2
SetKeyDelay, -1, 500
ControlSend, Edit1, This is a line of text in the notepad window., Notepad |
|
|
| Back to top |
|
 |
Carnifex
Joined: 10 Nov 2009 Posts: 11
|
Posted: Tue Nov 10, 2009 11:51 am Post subject: |
|
|
I appreciate the help guys !
@amazed, it was a wild guess if "A_ThisLabel" would work with a ControlSend, thank you for explaining.
I know a Return was lacking from the wSend subroutine, it was a mere copy paste mistake from my original code.
@the last guest posting, I know it works with normal text I'm talking about pushing keys down and releasing them again. {Up down}{Up up} etc.
I'm first trying out some other stuff and will post back here if anything resolves the issues. |
|
| Back to top |
|
 |
Carnifex
Joined: 10 Nov 2009 Posts: 11
|
Posted: Tue Nov 10, 2009 3:33 pm Post subject: |
|
|
| Code: | SetTitleMatchMode, 2
SetKeyDelay, 100, 1000
ControlSend,, {up down}{up up}, ahk_id %handle% |
Doesn't work. |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Nov 10, 2009 5:56 pm Post subject: |
|
|
| Quote: | Can you show the full syntax for that?... | Code: | ControlSend,, a, ahk_id %handle%
SetKeyDelay, -1, 5000 |
|
o ic, sorry i misunderstood ur question
the below script still works perfectly in notepad
| Code: | SetTitleMatchMode, 2
SetKeyDelay, -1, 500
ControlSend, Edit1, {shift down}123abc{shift up}, Notepad |
it does show "!@#ABC" instead of "123abc"
so the bottom line is down/up buttons works in ControlSend, probably the issue is the window u are using does not support it |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Tue Nov 10, 2009 6:30 pm Post subject: |
|
|
I fail to understand why you're using ControlGet to get the window's HWND. Does it not work if you specify WinTitle in ControlSend itself? There doesn't appear to be any unique designation in your code that should stop it. There are also easier ways to retrieve the HWND:
| Code: | handle:=WinExist("WinTitle")
;ControlGet, handle, Hwnd,,, WinTitle |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Carnifex
Joined: 10 Nov 2009 Posts: 11
|
Posted: Wed Nov 11, 2009 1:09 am Post subject: |
|
|
| sinkfaze wrote: | I fail to understand why you're using ControlGet to get the window's HWND. Does it not work if you specify WinTitle in ControlSend itself? There doesn't appear to be any unique designation in your code that should stop it. There are also easier ways to retrieve the HWND:
| Code: | handle:=WinExist("WinTitle")
;ControlGet, handle, Hwnd,,, WinTitle |
|
ControlGet does the same thing.
I still can't get it to work.. I guess the window isn't supporting it indeed.
| Code: |
SetKeyDelay, -1, 1000
ControlSend,, {up down}{up up}, ahk_id %handle%
|
Just does nothing. I've tried changing both parameter values, but it doesn't matter.
I might have found the problem.
For some reason ControlSend just ignores the second parameter in SetKeyDelay.
So it reads SetKeyDelay, 500, -1
but not SetKeyDelay, 500, 1000
It's not pressing down buttons, it just spams them.
Last edited by Carnifex on Wed Nov 11, 2009 1:32 am; edited 2 times in total |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 780 Location: England
|
Posted: Wed Nov 11, 2009 1:24 am Post subject: |
|
|
Carnifex, have you tried any other send modes like SendPlay or SendInput? You may have already tried these, but I just thought I would check
| Code: | wSend:
SendPlay {Up down}
Sleep 1000
SendPlay {Up up}
; =====
; OR
; =====
SendMode, InputThenPlay
SendInput {Up down}
Sleep 1000
SendInput {Up up}
Return |
|
|
| Back to top |
|
 |
Carnifex
Joined: 10 Nov 2009 Posts: 11
|
Posted: Wed Nov 11, 2009 1:27 am Post subject: |
|
|
| OceanMachine wrote: | Carnifex, have you tried any other send modes like SendPlay or SendInput? You may have already tried these, but I just thought I would check
| Code: | wSend:
SendPlay {Up down}
Sleep 1000
SendPlay {Up up}
; =====
; OR
; =====
SendMode, InputThenPlay
SendInput {Up down}
Sleep 1000
SendInput {Up up}
Return |
|
I know those work, but that would require the game to be the active window, which I don't want. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|