|
Post by Johnc on Jul 3, 2018 19:03:17 GMT
Hi Steve,
Need a way to exit an infinite loop with a keypress.
Explored the "KEYBOARD PRESS" conditional command:
IF | KEYBOARD KEYPRESS | Keypress \ | IS | CONTINUE
but I need something different such that the MMM script cannot wait indefinitely for a keystroke. It has to continue the loop if the predetermined key is not pressed within 10 seconds for example.
i.e.
1 do work1 2 do work2 3 do work3 4 If there is no keypress "\" within 10 seconds goto line 1, else exit MMM
Any ways to do this in MMM?
Thanks in advance!
|
|
|
Post by mannymcmouseface on Jul 3, 2018 23:01:19 GMT
Hi John,
The KEYBOARD KEYPRESS object is best used (should only be used) with a CONTINUE action. Like this:
4 | IF | KEYBOARD KEYPRESS | Keypress \ | IS | CONTINUE This doesn't help your loop break. Your better to use a different environmental queue to a positive condition that breaks the loop.
A time works but you MUST know the current time for this to work. For this example the current time is 8:27:20 AM, the target time is +10 seconds at line 4.
1 work1 2 work2 3 work3 4 | IF | TIME | 8:27:30 AM | IS AFTER CURRENT TIME | GOTO MACRO LINE | 1 | ELSE | 5 | RUN ACTION | | | | EXIT
Other alternatives: Network Packet from local host within 10 seconds:
4 | IF | NETWORK PACKET DETECTED | Local Area Connection 1 | SOURCE ADDRESS | 127.0.0.1::10000 | GOTO MACRO LINE | 1 | ELSE | 5 | RUN ACTION | | | | EXIT File exist on a 10 second loop:
1 | RUN ACTION | | | | DEFINE INTEGER VARIABLE | %INTEGER4%::0 2 | RUN ACTION | | | | RUN VIA CMD /C | ping -n 2 127.0.0.1 3 | RUN ACTION | | | | WAIT SECONDS | 1 4 | IF | FILE | C:\temp\check.txt | EXIST | GOTO MACRO LINE | 1 5 | IF | INTEGER VARIABLE | %INTEGER4% | >= | 10 | STOP | ELSE | 4 | RUN ACTION | | | | GOTO MACRO LINE | %return%-1
Hope this helps.
|
|
|
Post by Johnc on Jul 3, 2018 23:53:34 GMT
Thanks mannymcmouseface for your creative suggestions. Appreciated! However, the time to force a loop exit can be different every time and therefore the best input requires a human decision.
It would be ideal if the "CONTINUE" loop has a time-out parameter such that it will not wait forever for a keypress input. It will just "auto" continue after 10S for example, if no keypress is detected.
Hmm... maybe I can use the mouse position! If I wanna exit the loop, I will just move the mouse to the lower right maybe?? Not sure if it works... Need to try it!
|
|
|
Post by Johnc on Jul 4, 2018 0:29:21 GMT
I am getting close!
1 | IF | MOUSE POSITION EQUALS | {X=100,Y=100} | GREATER THAN | MESSAGE PROMPT | ok::ok | ELSE | 1 | RUN ACTION | | | | GOTO MACRO LINE | 4
2 | RUN ACTION | | | | WAIT SECONDS | 5
3 | RUN ACTION | | | | GOTO MACRO LINE | 1
4 | RUN ACTION | | | | STOP
The macro actually stopped when I moved the mouse to upper left but it did not exit the macro loop! It seemed to be waiting for something! Moving the mouse away from the upper left resumed the loop!! Any insights?? Tks!
|
|
|
Post by Johnc on Jul 4, 2018 0:31:30 GMT
replacing line 4 with:
4 | RUN ACTION | | | | EXIT
made no difference!
|
|
|
Post by mannymcmouseface on Jul 4, 2018 4:25:47 GMT
Hi,
I think this is what your after John.
1 | RUN ACTION | | | | WAIT SECONDS | 5 2 | IF | MOUSE POSITION NEAR | {X=100,Y=100} | IS | WAIT MILLISECONDS | 1 | ELSE | 2 | RUN ACTION | | | | STOP 3 Do actions 4 Do actions 5 Do actions 6 | RUN ACTION | | | | GOTO MACRO LINE | 1
1 - 5 seconds to move the mouse near 100 100 2 - if the mouse is near 100 100 then wait 1 ms (basacally just do nothing) - if the mouse is not near 100 100 then STOP the macro 3 - 4 - 5 - do your macro whatever it may be 6 - go back to line 1
|
|
|
Post by Johnc on Jul 5, 2018 16:07:56 GMT
Hi mannymcmouseface, (r u Steve BTW?)
Somehow your script doesn't quite work... It keeps looping without stopping. Looks like the "MOUSE POSITION NEAR" condition is not very reliable. My test example using "MOUSE POSITION" Greater than worked better... Not sure why... Tks!
1 | RUN ACTION | | | | WAIT SECONDS | 5
* | 2 | IF | MOUSE POSITION NEAR | {X=100,Y=100} | IS | WAIT MILLISECONDS | 1 | ELSE | 2 | RUN ACTION | | | | STOP
* | 3 Do actions
5 | RUN ACTION | | | | MESSAGE PROMPT | ok::ok
* | 5 Do actions
6 | RUN ACTION | | | | GOTO MACRO LINE | 1
|
|