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 

keywait forever.

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



Joined: 09 Nov 2009
Posts: 61

PostPosted: Sat Nov 21, 2009 3:21 am    Post subject: keywait forever. Reply with quote

is there any wait to keep running a KeyWait all the time (during the script)
I'm doing this: if nobody press a specific key (example: f) after 20 seconds, then open notepad. If someone press "f" key, start again counting 20 second, waiting for a new "f" key pressed, and allways do the same.

I tried with this script, but it only works 1 time.

Code:
keyWait, f,D T20
if ErrorLevel = 1
goto, closing

closing:
Run, Notepad.exe
Return


Thanks
Back to top
View user's profile Send private message
i3egohan



Joined: 18 Jul 2006
Posts: 401

PostPosted: Sat Nov 21, 2009 3:30 am    Post subject: Reply with quote

Code:
Loop
{
    KeyWait, f,D T20
    if ErrorLevel = 1
    Gosub, closing
}

closing:
Run, Notepad.exe
Return


Read about Goto and GoSub in the manual. They have big diffrences and to remain control flow and a good coding practice you should hardly ever use Goto unless its actually needed.
Back to top
View user's profile Send private message
alexisfch2
Guest





PostPosted: Sat Nov 21, 2009 4:29 am    Post subject: Reply with quote

thanks i3egohan, im trying to brake the loop if nobody press "f" key after 20 seconds (after that notepad is open) and continue the loop (searching for "f" key after that someone press "f" key, I tried with this, but I can't:

Code:
Loop
{
    KeyWait, f,D T20
    if ErrorLevel = 1
    Gosub, closing
break
    if ErrorLevel = 0
continue
}
Return

closing:
Run, Notepad.exe
Return
Back to top
i3egohan



Joined: 18 Jul 2006
Posts: 401

PostPosted: Sat Nov 21, 2009 5:01 am    Post subject: Reply with quote

You mean if someone presses 'f' it starts the loop again? And only opens notepad after 20 seconds?

Heres the above.

Code:
Loop
{
    KeyWait, f,D T20
    if ErrorLevel = 1
   Continue
    Gosub, closing
}

closing:
Run, Notepad.exe
Return


And heres one which opens notepad even if f has been pressed

Code:
Loop
{
    KeyWait, f,D T20
    if ErrorLevel = 1
    {
        Gosub, closing
   Continue
    }
    Gosub, closing
}

closing:
Run, Notepad.exe
Return


If they dont suit your needs i still dont understand what you mean
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 882
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Sat Nov 21, 2009 6:34 am    Post subject: Reply with quote

Or...
Code:
Loop
{
  KeyWait, f,D T20
  If !ErrorLevel
    Run, Notepad.exe
}

_________________
Antonio França
aka MasterFocus aka Tunis
+ My AHK stuff: ~MasterFocus
+ AHK @ irc.freenode.net: #ahk
Contact: PM only !
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 499
Location: Berlin / Germany

PostPosted: Sat Nov 21, 2009 6:48 am    Post subject: Reply with quote

Code:
#NoEnv
X := A_ScreenWidth // 2
Y := A_ScreenHeight // 2
TimeOut := 5
Loop {
   Loop {
      ToolTip, Loop waiting for "f", X, Y
      KeyWait, f, D T%TimeOut%
      If (ErrorLevel) {
         Gosub Action
         Break
      }
      ToolTip, Got the "f" in time!, X, Y
      Sleep, 500
   }
   ToolTip, Waiting for next "f", X, Y
   KeyWait, f, D
   KeyWait, f
}
ExitApp
Action:
   MsgBox, Loop timed out!
Return
Question
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
alexisfch



Joined: 09 Nov 2009
Posts: 61

PostPosted: Sat Nov 21, 2009 3:13 pm    Post subject: Reply with quote

maybe im not explaning my position well, I need:

If nobody press "f" during these 20 second -> run notepad and break the loop
If somebody press "f" (for example: on 15th second) start the count down again, (continue the loop)
Back to top
View user's profile Send private message
:?:
Guest





PostPosted: Sat Nov 21, 2009 3:59 pm    Post subject: Reply with quote

Code:
Timer("20")

Timer(x) {
 Loop, {
  KeyWait, f, D T%x%
  If(ErrorLevel) {
     Run, notepad.exe
     Break
  }
 }
}

Question [/code]
Back to top
alexisfch



Joined: 09 Nov 2009
Posts: 61

PostPosted: Sun Nov 22, 2009 3:19 am    Post subject: Reply with quote

I'm trying to do this:

If nobody press a specific key (example:enter) after 20 seconds, press "enter" 1 time and continue with other keywait (keyWait, enter,D 10) if nobody press "enter" in these 10 seconds, press "enter" and continue with a last keywait (keyWait, enter,D 5)

But if someone press "enter" key before these first 20 seconds (ex: on the 5th second), then continue with the second keywait and after that with the last keywait
5 (first "enter" key pressed ) + 10 (2nd keywait) + 5 (3th keywait)

Thanks
Back to top
View user's profile Send private message
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