| View previous topic :: View next topic |
| Author |
Message |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Sun Dec 13, 2009 5:09 pm Post subject: two loops at same time |
|
|
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] |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
Posted: Sun Dec 13, 2009 5:17 pm Post subject: |
|
|
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 
Last edited by HotKeyIt on Mon Dec 14, 2009 5:59 am; edited 1 time in total |
|
| Back to top |
|
 |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Sun Dec 13, 2009 9:27 pm Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Sun Dec 13, 2009 10:27 pm Post subject: |
|
|
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."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
Posted: Mon Dec 14, 2009 2:46 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Mon Dec 14, 2009 5:30 pm Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Mon Dec 14, 2009 5:49 pm Post subject: |
|
|
_________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Mon Dec 14, 2009 10:15 pm Post subject: |
|
|
| 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
}
}
|
|
|
| Back to top |
|
 |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Tue Dec 15, 2009 5:45 pm Post subject: |
|
|
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 |
 |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Tue Dec 15, 2009 6:38 pm Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
alexisfch
Joined: 09 Nov 2009 Posts: 92
|
Posted: Tue Dec 15, 2009 6:47 pm Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
|
| Back to top |
|
 |
|