AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to delay action of button pressed?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
mccoy178
Guest





PostPosted: Tue Aug 30, 2005 5:17 am    Post subject: How to delay action of button pressed? Reply with quote

Hello. I am from the www.byoac.com forums. We are using AHK in a script to help with the games we play. We build arcade machines, and we are using a program that when "P" is pressed, the game is paused, a small program that shows what the controls are pops up, and when "P" is pressed again, the game resumes. The problem we are having is that when "P" is pressed to pause the game, the game pauses and the controls pop up properly; when "P" is pressed to exit the controls viewer and resume the game, the game remains paused. Please take a look at the script and see what you think. I have tried replacing sleep with StatusBarWait 250, and nothing still. I don't know if the command is in the wrong place or what is going on. Thank you so much for the help.

The Script:
Code:
#SingleInstance force
#Persistent
; The asterisk prefix makes the remapping more complete on XP/2k/NT. For 9x systems you can remove it.
DetectHiddenWindows, On

~P::
{
   If ScreenState =1

   {
      send, {Escape down}
      send, {escape up}

      WinActivate,%Title%
      WinRestore,%Title%
      WinActivate,%Title%
      WinWaitActive,%Title%
      [b]sleep 250[/b]
      Send,{p down}{p up}
      ScreenState=0
   }
   else
   {
      WinGetActiveTitle, Title
      J5=Johnny5.exe %1% -ahk
      if 0 >1
         J5=%J5%  -clone %2%
      if 0 >2
         J5=%J5%  -driver %3%

      Run,%J5%, G:\Development DON'T ERASE\sources\Controls Viewer3\, max
      ScreenState=1
   }
}
return
~Escape::
if ScreenState=1
{
      WinActivate,%Title%
      WinRestore,%Title%
      WinActivate,%Title%
      WinWaitActive,%Title%
      [b]sleep 250[/b]
      Send,{p down}{p up}
      ScreenState=0
}
else
{
   ExitApp ; Assign a hotkey to terminate this script.
}

return
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Wed Aug 31, 2005 12:10 am    Post subject: Reply with quote

When you create a tilde hotkey such as ~P, the P keystroke passes through to the active window the moment you physically press it. Because of this, there might be no need for the following line, which sends another P keystroke:

Send,{p down}{p up}

If that doesn't help, you can try opening the script's main window via its tray icon. By default, it displays the lines most recently executed, which can help debug a script. You can also select View > Key History from the menu bar to find out exactly what keystrokes are being sent.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Wed Aug 31, 2005 1:10 am    Post subject: Reply with quote

The problem we are having is that when "P" is pressed the second time to close the controls program and unpause the game, the game is not getting the "P" keystroke. I believe some sort of delay is needed, I just don't know where. Please watch these videos and see if you understand what I mean. Again, thanks for the help.

http://media.putfile.com/Script1

http://media.putfile.com/Script2
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Wed Aug 31, 2005 11:11 am    Post subject: Reply with quote

Quote:
I believe some sort of delay is needed, I just don't know where.
You can try different settings of SetKeyDelay. For example:

SetKeyDelay, 50, 50

You can also have explicit control over the delay with something like:
Send {P down}
Sleep 50
Send {P up}

If this doesn't help, I think the best approach is to understand exactly what keystrokes the game expects (and when) and compare them to the keystrokes the script is actually sending. The first step is to ensure the script is actually executing the way you expect, which is done by checking its execution history in the main window.
Back to top
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Wed Aug 31, 2005 11:31 am    Post subject: Reply with quote

Hi, I have restructure the code, I hope it helps. Please give it a try
Code:
#SingleInstance force
#Persistent
DetectHiddenWindows, On

J5=Johnny5.exe %1% -ahk
if 0 >1
   J5=%J5%  -clone %2%
if 0 >2
  J5=%J5%  -driver %3%

ScreenState := False
return

ReactivateGame:
  Send, {Escape down}
  Sleep, 50
  Send, {Escape up}

  WinRestore,%Title%
  WinActivate,%Title%
  WinWaitActive,%Title%

  Send, {p down}
  Sleep, 50
  Send, {p up}
return

$p::
   If ScreenState
       GoSub, ReactivateGame
   else
   {
      WinGetActiveTitle, Title
      Send, {p down}
      Sleep, 50
      Send, {p up}
      Run,%J5%, G:\Development DON'T ERASE\sources\Controls Viewer3\, max
   }
  ScreenState := not ScreenState
return

~Escape::
  if ScreenState
       GoSub, ReactivateGame
  else
     ExitApp
  ScreenState := not ScreenState
return

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mccoy178
Guest





PostPosted: Wed Aug 31, 2005 5:00 pm    Post subject: Reply with quote

Thank you for the script. It does the same thing as the other. Two things, first, when a game is started, the j5 viewer (control Program), is started by the same app. that started the game. When the game is launched, it is behind a blank screen for J5. Is there a way to fix that? Second, I dont understand why the game is not picking up the "P" other than until "P" is released, the j5 screen does not disappear. Could this effect how the game is getting the instructed "p"? It is wierd because it seems to receive it about a third of the time. Thanks again for all your help. By the way, this program is being used for private use ony. I don't want you guys to think this has anything commercial to do with it.
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Wed Aug 31, 2005 6:05 pm    Post subject: Reply with quote

Hí McCoy,
I have problems to understand what you wrote.
But maybe it is time you start to play with the game and learn more about AHK. It is not that difficult.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mccoy178
Guest





PostPosted: Wed Aug 31, 2005 7:15 pm    Post subject: Reply with quote

Quote:
I have problems to understand what you wrote.
But maybe it is time you start to play with the game and learn more about AHK. It is not that difficult.


Good advice.

The problem that I am having is that the game is not being unpaused after the controls program is exited. The game requires the pressing of "P" to unpause it. The game is only becoming unpaused about 1/3rd of the time. I understand the AHK is not complicated, but this has me stumped. Confused
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Thu Sep 01, 2005 2:22 am    Post subject: Reply with quote

It's probably a keystroke timing issue, or perhaps the keystroke is being sent at the wrong time (when the game isn't prepared to receive it).

But you've probably tried all kinds of delays and such. If so, you might want to try ControlSend. If that doesn't work you might try Rajat's SendMessage Tutorial to determine what message the game receives (if any) when you unpause it. You could then send that message via SendMessage.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group