Moving bar pickup

Asked by Jakob on 2018-01-13

So for most of the day I've been attempting to set up a code that would pickup a pixel pattern and press space bar.

So far I've:

if exists(picture1) or exists(picture2):
   type(Key.SPACE)
   continue

The string will pick up and work occasionally but on 2/3 of the time it'll either click early or late.
Any recommendations?

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-01-15
Last reply:
15 hours ago
masuo (masuo-ohara) said : #1

if you want to confirm these images exist without wait time, set waiting time zero.
http://sikulix-2014.readthedocs.io/en/latest/region.html?#Region.exists

if exists(picture1,0) or exists(picture2,0):
   type(Key.SPACE)

Jakob (jakobpk) said : #2

Setting times to 0 helped with the fighting aspect and I thank you, atm my code is this:

        if Region(785,569,352,31).exists("1516053159102.png",0):
                if Region(785,569,352,31).exists("1516053159102.png",0):
                    type(Key.SPACE,0)
                    continue
                else:
                    continue
        else:
            continue

While adding more if statements seems to help the same issue occurs regardless, it seems as if the screen flickers the wrong info to trick the program into activating late or early, is there any way I can set an exposure time kind of thing?

masuo (masuo-ohara) said : #3

Did you measure turnaround time of each exists() function?
You should understand the phenomenon before thinking about countermeasures.

If you want to repeat the exact same search, use while or for statement.
r = Region(785,569,352,31)
while True:
    if r.exists("1516053159102.png",0):
        type(Key.SPACE,0)
    sleep(1)

And if you don't read basic behavior, this is helpful for your understanding.
http://sikulix-2014.readthedocs.io/en/latest/basicinfo.html#sikulix-how-does-it-find-images-on-the-screen

TestMechanic (ndinev) said : #4

Jakob,
Here is some ideas worth exploring:
-- what is the timing between appearance and actions you are looking for. Is this in range of seconds or ms?
-- UI focus. Sikuli will type keys against currently focused element of the active window. In my practice I observed many cases where in transition between screens/actions the focus can temporarily be lost. Investigate this possibility.
-- executing aggresive image finding commands will load your cpu and may impact behaviour of your app

Hope this helps

Can you help with this problem?

Provide an answer of your own, or ask Jakob for more information if necessary.

To post a message you must log in.