Help with Script Dealing With Image That Repeats

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

nycgirleo
Newbie
Posts: 4
Joined: Mon Mar 16, 2009 1:30 am

Help with Script Dealing With Image That Repeats

Post by nycgirleo » Mon Mar 16, 2009 1:50 am

Hello all!

I am new at this and I'm trying to create a script but I am having problems. I don't know how to make it run continuously without me having to keep clicking on run. I captured some screenshots already and tried to create a script but had no luck. Not sure if this is that hard or not but this is what I want to do:

1. When the program sees image0 (I took a screenshot of all the images and saved it as bitmap files) it will move the mouse to image0 and clicks on it. (Completed)

2. Then when the program sees image1, it will press 1 on the keyboard. (No clue at all)

3. If the program does not see image1, but sees image2 instead, it will press 2. (No clue at all)

4. If the program does not see image1, or image2, but sees image 3 instead, it will press 3. (No clue at all)

For steps 2-4 I want to make it run continuously since the images can repeat more than once. For example, image1 will show first, then image2, then image1, then image3, then image2, etc.

5. If the program does not see any of those 3 images anymore after lets say 5 seconds, it will move the mouse to image4 and click on it. (No clue at all)

6. Then it will go back to step 1 again and this program keeps repeating. (No clue at all)

Is this something that can easily be made? I wish I was a pro at this.

Thanks for your help!
Last edited by nycgirleo on Tue Mar 17, 2009 9:03 pm, edited 1 time in total.
William Ng

mmcbrien
Newbie
Posts: 7
Joined: Thu Jul 31, 2008 9:53 pm

Post by mmcbrien » Tue Mar 17, 2009 1:04 pm

Several different ways you could accomplish this. But using the FIP command look for the first image, if the result>1 the the image was located then do a subroutine else like for the next image. ta the end of the commands loop back to the top and do it again.

nycgirleo
Newbie
Posts: 4
Joined: Mon Mar 16, 2009 1:30 am

Post by nycgirleo » Tue Mar 17, 2009 9:12 pm

Thanks mmcbrien. I almost got it to work. The problem that I am having now is that when the program sees the image and it sends a text, the text does not type in the window I want it to. I even tried focusing it and it still doesn't work. If I used notepad it would work. But it is not working if I use a web browser. I want it to work in a flash game if that helps. How can I fix this problem?
William Ng

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Try setting focus with mousemove and LClick

Post by gdyvig » Wed Mar 18, 2009 4:10 am

I'm guessing you tried using SetFocus.

Try setting focus by doing a mousemove to the coordinates found by FIP. Then LClick, or whatever you would do manually, then send the key strokes.

Does that help?

Gale

nycgirleo
Newbie
Posts: 4
Joined: Mon Mar 16, 2009 1:30 am

Post by nycgirleo » Wed Mar 18, 2009 5:53 pm

I tried that and it still does not work.
William Ng

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Press or SendText

Post by gdyvig » Wed Mar 18, 2009 6:01 pm

You mention pressing the numeric keys.

If you haven't already, try the SendText command instead of Press/Release. I don't know if Press works with all keys.

Gale

nycgirleo
Newbie
Posts: 4
Joined: Mon Mar 16, 2009 1:30 am

Post by nycgirleo » Wed Mar 25, 2009 11:01 pm

I tried the SendText command and it wont send. I think it probably sends but the flash game does not detect it. If I manually press the keys it will work. If I use the program to send the keys, it won't work.
William Ng

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

flash does not detect key presses

Post by gdyvig » Thu Mar 26, 2009 4:09 am

Hi Marcus,

I confirmed the problem on a web site with a flash demo. You must click on the movie clip area to activate flash, then press various keys to make an object move. The Press and Send> commands do not work. Neither does vbscript's sendkeys, though I may have used it incorrectly.

I tried activating the movie clip area with a mousemove and and LClick. Then I tried finding the window with View System Windows and doing SetFocus on the handle. SetFocus could not find the Window Title. None of that works.

The adobe documentation says Flash responds to keypress events. Does Macro Scheduler not produce a true keypress event?

Thanks,

Gale

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Found answer: Press NP#

Post by gdyvig » Thu Mar 26, 2009 3:19 pm

Hi,

I found a Flash example where you move an object around by clicking the arrow keys. My keyboard has 4 arrow keys in a cluster and 4 more arrow keys in the numeric keypad. Any of these eight keys will work provided Num Lock is turned off when you run the Flash example manually.

These Macro Scheduler commands do NOT work with Flash for me:
Press Left
Press Right
Press Down
Press Up
These Macro Scheduler commands DO work with Flash for me:
NumOff
Press NP4
Press NP6
Press NP2
Press NP8
See if the Press NP# commands work for you.

Gale

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: Found answer: Press NP#

Post by jpuziano » Thu Mar 26, 2009 3:44 pm

gdyvig wrote:I found a Flash example where you move an object around by clicking the arrow keys.
Hi Gale,

Please post the url to the flash example you tried... so we can try the same thing.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Flash sites using Arrow Keys

Post by gdyvig » Thu Mar 26, 2009 5:03 pm

Here is a site with a sample and a good explanation of key ascii codes vs key codes:

http://www.flash-creations.com/notes/asclass_key.php


The Numeric Keypad solution may not be such a good one if you do not have one.

Gale

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Flash sites using Arrow Keys

Post by Marcus Tettmar » Thu Mar 26, 2009 5:20 pm

gdyvig wrote:The Numeric Keypad solution may not be such a good one if you do not have one.
Doesn't matter. Macro Scheduler can still send the keystrokes. Whether you have a physical key or not it still exists. Unplug your keyboard and then run a macro which sends keystrokes. It will work. NP keys are valid keys in Windows and the VK codes exist whether or not you have a numeric keypad on your keyboard! :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Mar 26, 2009 6:20 pm

Is that independent of the Num Lock setting (which would be unlike the way Caps Lock works)?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Mar 26, 2009 7:15 pm

Hi Gale,

Interesting. I used the following script to test:
//http://www.mjtnet.com/forum/viewtopic.php?t=5402
//http://www.flash-creations.com/notes/asclass_key.php

//test - press arrow down key 10 times - does flash movie respond?

//add delay to be able to set focus back on the flash movie
Wait>10

Press Down * 10
I set F11 as a Hot Key in MS to the above script to make it easier to test.

Note that there are two separate "flash movies" on the web page at the link you sent.

The top one just under the heading Continuous checking and responding to keyboard activity responds fine to the MS macro.

However, the second one doesn't respond at all... the one located under the section that says:
  • Using an onEnterFrame checker and looking for Key.isDown instead can produce a much more responsive result (including response to multiple keys). Here is the same movie running at 21fps (same as above) using an onEnterFrame loop to check and respond (code follows):
My guess as to why... is as follows.

In the second flash movie, the flash code is actively checking for a condition... the condition of the key being down. When our fingers tap a key, that key is down for a good long time so the flash code can pick it up. When the MS script simulates the key being down... the duration may be incredibly short therefore the flash code is not picking it up.

Another possibility is that maybe MS does not actually simulate the key down condition... and if so then the flash code will never see it. Perhaps MS just sends a code to the keyboard buffer.

Marcus, can you elaborate a bit on what may or may not be happening to cause the above?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

More flash demos

Post by gdyvig » Fri Mar 27, 2009 2:48 pm

My first test was against a demo found on the Adobe site.
I tried Press Left, Send>4 with no success.
Then I logged off.
Next I added Press NP4 to the script, leaving the other commands in.
I could not find that Adobe site, but found the another - the one referenced in a previous post.
The script worked, so I thought it was the Press NP4 that did it.
Actually it was the Press Left.

Now I found another Adobe demo, neither Press NP4 nor Press Left works. Perhaps the same issue that JRL brought up on demo2 in the previous post.

http://www.adobe.com/support/flash/inte ... keyobject/

Pressing the spacebar does not work either.

JRL said it may have to do with how long (or whether) the key is pressed before it is released. Perhaps a couple of new system variables like SK_PRESS_TIME and PRESS_TIME could specify that.





Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts