AutoHotkey Community

It is currently May 27th, 2012, 1:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: keywait forever.
PostPosted: November 21st, 2009, 4:21 am 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 4:30 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 5:29 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 6:01 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 7:34 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Or...
Code:
Loop
{
  KeyWait, f,D T20
  If !ErrorLevel
    Run, Notepad.exe
}

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 7:48 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
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
:?:

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 4:13 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 4:59 pm 
Code:
Timer("20")

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

:?: [/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 4:19 am 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, bobbysoon, iDrug, Tipsy3000 and 15 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