AutoHotkey Community

It is currently May 26th, 2012, 11:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 10th, 2009, 4:24 am 
Offline

Joined: November 10th, 2009, 3:57 am
Posts: 11
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 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 4:45 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 8:22 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 9:39 am 
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~


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 9:42 am 
u can use
Code:
SetKeyDelay
for controlsend


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 9:43 am 
o wait, help file did mention an example
Quote:
ControlSend, Edit1, {Alt down}f{Alt up}, Untitled - Notepad


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 10:18 am 
Anonymous wrote:
u can use
Code:
SetKeyDelay
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 10:23 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 12:51 pm 
Offline

Joined: November 10th, 2009, 3:57 am
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 4:33 pm 
Offline

Joined: November 10th, 2009, 3:57 am
Posts: 11
Code:
SetTitleMatchMode, 2
SetKeyDelay, 100, 1000
ControlSend,, {up down}{up up}, ahk_id %handle%


Doesn't work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 6:56 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2009, 7:30 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 2:09 am 
Offline

Joined: November 10th, 2009, 3:57 am
Posts: 11
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 November 11th, 2009, 2:32 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 2:24 am 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2009, 2:27 am 
Offline

Joined: November 10th, 2009, 3:57 am
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, hyper_, Leef_me, Pulover, rbrtryn, XstatyK and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group