AutoHotkey Community

It is currently May 27th, 2012, 12:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: two loops at same time
PostPosted: December 13th, 2009, 6:09 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
im trying to use two different Loop in the same time,
if nobody press "a" key after 20 seconds, run notepad.exe
if nobody press "s" key after 10 seconds, run explorer.exe

so, if im pressing "a" key during 20 seconds, but if I don't press "s" key in these 20 seconds, run explorer.exe, If nobody press "a" and "s" key during 30 seconds (20 + 10) run notepad.exe and explorer.exe

I tried with this code, but doesn't work, because only work the first loop (akey)


Code:
gosub, akey
gosub, skey
return

akey:
Loop
{
    KeyWait, a,D T20
    If(ErrorLevel) {
run notepad.exe
exitapp
    Break
  }
}

skey:
Loop
{
    KeyWait, s,D T10
    If(ErrorLevel) {
run explorer.exe
exitapp
    Break
  }
}


[Deleted double post. ~jaco0646]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 6:17 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Try:
Code:
SetTimer, key, 100
a:=A_TickCount
s:=A_TickCount

return

~a::
   a:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-a>20000){
      run notepad.exe
      a:=A_TickCount
      If (A_TickCount-s>11000)
         exitapp
   } else if (A_TickCount-s>10000){
      run explorer.exe
      s:=A_TickCount
      if (A_TickCount-a>21000)
         exitapp
   }
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on December 14th, 2009, 6:59 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 10:27 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
HotKeyIt wrote:
Try:
Code:
SetTimer, key, 100
return

~a::
   a:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-a>20000){
      run notepad.exe
      a:=A_TickCount
      If (A_TickCount-s>11000)
         exitapp
   } else if (A_TickCount-s>10000){
      run explorer.exe
      s:=A_TickCount
      if (A_TickCount-a>21000)
         exitapp
   }
Return


it doesn't work, can anybody help me?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2009, 11:27 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
You may try GetKeyState. Here's an example:
Code:
;--------------------
time := 5000
key := "a"
;--------------------
start := A_TickCount
Loop
{
  ToolTip, % A_TickCount - start ; this is removable
  ; for each new key, you may add a new IF statement
  If ( !GetKeyState(key) AND ( A_TickCount - start >= time ) )
  {
    MsgBox !!!
    ; put here actions to be performed
    Break ; don't remove this
  }
}

_________________
"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: December 14th, 2009, 3:46 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Try again this, for testing I have replaced the run with a ToolTip and set to 2 and 1 second instead 20 and 10:
Code:
SetTimer, key, 100
a:=A_TickCount
s:=A_TickCount
return

~a::
   a:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-a>2000){
      ToolTip a %A_Hour%:%A_Min%:%A_Sec%
      a:=A_TickCount
;~       If (A_TickCount-s>11000)
;~          exitapp
   } else if (A_TickCount-s>1000){
      ToolTip s %A_Hour%:%A_Min%:%A_Sec%
      s:=A_TickCount
;~       if (A_TickCount-a>21000)
;~          exitapp
   }
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2009, 6:30 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
Thanks HotKeyIt, is there any way to break the loop when any of these two event happen, (I mean when run notepad.exe or explorer.exe)


Code:
SetTimer, key, 100
a:=A_TickCount
s:=A_TickCount
return

~a::
   a:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-a>20000){
      run notepad.exe
      a:=A_TickCount
;~       If (A_TickCount-s>11000)
;~          exitapp
   } else if (A_TickCount-s>10000){
      run explorer.exe
      s:=A_TickCount
;~       if (A_TickCount-a>21000)
;~          exitapp
   }
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2009, 6:49 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Code:
SetTimer, key, Off

_________________
"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: December 14th, 2009, 11:15 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
MasterFocus wrote:
You may try GetKeyState.


I tried with this but doesn't work totally
Code:
;--------------------
time1 := 5000
time2 := 10000
key1 := "a"
key2 := "s"
;--------------------
start := A_TickCount
Loop
{
  If ( !GetKeyState(key1) AND ( A_TickCount - start >= time1 ) )
  {
run notepad.exe
    Break ; don't remove this
  }
If ( !GetKeyState(key2) AND ( A_TickCount - start >= time2 ) )
  {
run explorer.exe
    Break ; don't remove this
  }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 6:45 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
[quote="HotKeyIt"][/quote]

Thanks HotKeyIt, I have a problem, im remapping an axis of my joystick to "up" arrow key with this script.

Code:
axisjoy:
GetKeyState, JoyY, JoyY
KeyToHoldDownPrev = %KeyToHoldDown%

if JoyY < 30
    KeyToHoldDown = up
else
    KeyToHoldDown =

if KeyToHoldDown = %KeyToHoldDownPrev%
    {
    if KeyToHoldDown
        Send, {%KeyToHoldDown% down}
    return
}

SetKeyDelay -1
if KeyToHoldDownPrev
    Send, {%KeyToHoldDownPrev% up}
if KeyToHoldDown
    Send, {%KeyToHoldDown% down}
return


and Im using the script you wrote with this remap, but it doesn't work, but when I press "up" on keyboard it works.
My final and wrong script is (Where is the problem?):

Code:
SetTimer, axisjoy, 5
SetTimer, key, 100
up:=A_TickCount
s:=A_TickCount
return

~up::
   up:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-up>5000){
      run notepad.exe
      up:=A_TickCount

   } else if (A_TickCount-s>10000){
      run explorer.exe
      s:=A_TickCount
   }
Return

axisjoy:
GetKeyState, JoyY, JoyY
KeyToHoldDownPrev = %KeyToHoldDown%

if JoyY < 30
    KeyToHoldDown = up
else
    KeyToHoldDown =

if KeyToHoldDown = %KeyToHoldDownPrev%
    {
    if KeyToHoldDown
        Send, {%KeyToHoldDown% down}
    return
}

SetKeyDelay -1
if KeyToHoldDownPrev
    Send, {%KeyToHoldDownPrev% up}
if KeyToHoldDown
    Send, {%KeyToHoldDown% down}
return


:shock: :shock: :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 7:38 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Code:
a::Settimer akey, Off
s::Settimer skey, Off
w::     ;w to start timers
Settimer akey, -20000
Settimer skey, -30000
Return

akey:
    Run notepad.exe
Return

skey:
    Run explorer.exe
Return

Is this what you ment?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 7:47 pm 
Offline

Joined: November 9th, 2009, 4:24 pm
Posts: 94
Sorry None, isn't I need to run two loops at same time,

loop 1, if nobody press "up" arrow key after 5 seconds, run notepad.exe
loop 2, if nobody press "s" key after 10 seconds, run explorer.exe

So If someone press "up"arrow key before 5 seconds just run explorer.exe (loop2)

I did it with this, and it works, but I'm using a joystick axis as "up" key, and here is my problem, because my script is not recognizing joystick axis as "up" arrow key .


Code:
SetTimer, key, 100
up:=A_TickCount
s:=A_TickCount
return

~up::
   up:=A_TickCount
Return

~s::
   s:=A_TickCount
Return

key:
   if (A_TickCount-up>5000){
      run notepad.exe
      up:=A_TickCount

   } else if (A_TickCount-s>10000){
      run explorer.exe
      s:=A_TickCount
   }
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2009, 4:05 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Look at this page to help get input from Joystick
http://www.autohotkey.com/docs/misc/RemapJoystick.htm


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, iDrug, Leef_me, Ohnitiel, rjgatito, Yahoo [Bot] 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