Hints, tips and tricks for newbies
Moderators: JRL, Dorian (MJT support)
-
Nagarules
- Junior Coder
- Posts: 24
- Joined: Tue Nov 21, 2006 9:33 pm
Post
by Nagarules » Tue Nov 21, 2006 9:40 pm
How can i make a loop until F5 is pressed on the keyboard?
for example:
Repeat>
Command 1
Command 2
Command 3
Command 4
Until> Waitkeydown>VK116
How can i convert what i just explained into Macro scheduler :S
-
Nagarules
- Junior Coder
- Posts: 24
- Joined: Tue Nov 21, 2006 9:33 pm
Post
by Nagarules » Tue Nov 21, 2006 10:15 pm
well, i have this:
OnEvent>KEY_DOWN,VK116,0,(Dont Know What Gos Here)
Label>start
wait>1
Send Character/Text>test
Press Enter
Goto>start
what do i do from here to make the macro pause itself or quit itself when vk116 is pressed :/
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Tue Nov 21, 2006 10:23 pm
Well, OnEvent calls a subroutine so you need a subroutine to handle the pause and you specify the subroutine name in OnEvent. This is how I would do it:
Code: Select all
OnEvent>KEY_DOWN,VK116,0,DoPause
Let>paused=false
Label>start
wait>1
SetFocus>Notepad*
Send Character/Text>test
Press Enter
//wait & do nothing if paused
Repeat>paused
//Do nothing
Wait>0.02
Until>paused=false
Goto>start
//Pause/Resume subroutine
SRT>DoPause
If>paused=false
Let>paused=true
Else
Let>paused=false
Endif
End>DoPause
Pressing F5 will pause the script. When F5 is pressed DoPause is called which first sets paused to true. The main loop will then run the Repeat/Until loop - doing nothing while paused=true. If F5 is pressed again paused is set to false, so the repeat/until loop in the main loop now exits and the main loop can continue.
Note however that you can pause macros just by pressing the Pause key on your keyboard.
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Tue Nov 21, 2006 10:26 pm
BTW - note that my example requires Notepad to be open. Notepad uses F5 for inserting date/time. So either use against another app, or change VK116 to VK115 to test against F4. It's just an example!
-
Nagarules
- Junior Coder
- Posts: 24
- Joined: Tue Nov 21, 2006 9:33 pm
Post
by Nagarules » Tue Nov 21, 2006 10:38 pm
Well i tried it this method and i have a little problem:
OnEvent>KEY_DOWN,VK115,0,pause
Label>start
wait>2
Send Character/Text>test
Press Enter
Goto>start
SRT>pause
WaitKeyDown>vk113
END>pause
-------
I wanted it to pause when i click F4 and resume when i click f2...
but this only works if i push F4 HARD on the keyboard for 1 second... i dont think i explained myself good enough
-
Me_again
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Post
by Me_again » Wed Nov 22, 2006 12:23 am
I think the problem is the Wait>2 It's not looking for keys when it's waiting.
-
Nagarules
- Junior Coder
- Posts: 24
- Joined: Tue Nov 21, 2006 9:33 pm
Post
by Nagarules » Wed Nov 22, 2006 6:30 am
So what should i add o.O?