|
Post by sansrisque on Mar 6, 2017 7:33:06 GMT
I am new to ankulua/lua and sikuli, but have used many programming language for years. I have been reading some of the lua and sikuli docs but struggling with a few thiings: I used a lua script to launch an app, and I want to wait until the application has finished launching and a certain pattern on the screen appears to click a button, seems trivial. Here's what I did to wait for the program to appear once launched: 1) ButtonPattern = Pattern("l.png"):similar(0.8) wait ( ButtonPattern , FOREVER ) --throws exception, says cant find the file/pattern 2) ButtonPattern = Pattern("l.png"):similar(0.8) while ( not (exists(ButtonPattern ) ) ) do toast ("waiting ....") wait (1) end --never find anything (loops)) 3) Launching the following lua AFTER the app has finished launching works however ! (but useless for what I am trying to do). of note the program that launched goes landscape mode ButtonPattern = Pattern("l.png"):similar(0.8) wait ( ButtonPattern , FOREVER ) --find the pattern This behavior doesnt seem to match the sikuli doc as i understand them. What am i missing? thanks for any help. sikulix-2014.readthedocs.io/en/latest/tutorials/surveillance/surveillance.htmlthis example monitors the desktop on a pc version
|
|
|
Post by AnkuLua on Mar 6, 2017 11:16:47 GMT
Do you use startApp() to launch the program in cases 1 and 2?
And you should put the device in landscape mode before running the script, just as the program to launch.
|
|
|
Post by Mercobots on Mar 6, 2017 11:32:25 GMT
hope that help
local function startAPP()
local img_sim = 0.8 local num_try = 2
for i = num_try, 0, -1 do if exists(Pattern("l.png"):similar(img_sim), 30) then return true elseif ("EX") then -- check another pattern EX: if update,if error elseif(i > 0) then -- lower the similarity img_sim = img_sim - 0.1 else -- nothing found return false return false end end end
startAPP()
this will try to find your pattern and never throws exception error
|
|
|
Post by sansrisque on Mar 7, 2017 5:50:11 GMT
Do you use startApp() to launch the program in cases 1 and 2? And you should put the device in landscape mode before running the script, just as the program to launch. Thx for quick feed back Yes in case 1 and 2 startApp() was used. Ran a quick test pushing the ankula play when overlaying a program running in portrait mode, and the detection in the program I run from the ankulua script then works. so great quick fix. ( I will have to fix my android home that doesn't do landscape mode right now and for which the build.prop edit doesnt work either.) The odd thing about this is that when I run the ankulua script from the home screen, the program launched does switch to portrait and then so does the position of the ankulua play button, i.e. it goes in portrait mode as well. The whole launch take about 45s, which is really long. Doesn't that mean that ankulua did get the portrait mode switch info? I dont know if that allows a fix to ankulua.... Is there is way to detect/switch the macro to portrait mode explicitly? Thanks for your program, time and help
|
|
|
Post by sansrisque on Mar 7, 2017 6:04:53 GMT
hope that help local function startAPP()
local img_sim = 0.8 local num_try = 2
for i = num_try, 0, -1 do if exists(Pattern("l.png"):similar(img_sim), 30) then return true elseif ("EX") then -- check another pattern EX: if update,if error elseif(i > 0) then -- lower the similarity img_sim = img_sim - 0.1 else -- nothing found return false return false end end end
startAPP()
this will try to find your pattern and never throws exception error Great function, thanks for the help! I can use this for another issue I have : ) I never used a pure exception based language, I got to be more careful to that!! I dont know however if this can help me to work around the fact that ankula script did not detect the portrait switch to landscape however. In this case, I am not sure what pattern to even pass it and how it sees the screen since it seem to still thinks it is running in portrait mode even though it adjusted its own display to landscape mode and my external app only runs in landscape mode..... I would think sikuli had dealt with the issue of portrait/landscape but I just started to look at all this, and sikuli seem to be mainly for fix screen activity, so may be not, and I haven't absorbed yet the discrepancy between ankulua and sikuli... Thx again for your help
|
|
|
Post by AnkuLua on Mar 7, 2017 6:29:24 GMT
Just start your script in landscape mode. Even the home page is in portrait mode. It's always recommended to start the script in the app.
|
|
|
Post by Mercobots on Mar 7, 2017 18:48:00 GMT
you can always use the getAppUsableScreenSize() and check the screen width -- suppose we start on landscape local screen = getAppUsableScreenSize() local landscape_width = screen:getX()
for i = 1, 3 do local screen_width = getAppUsableScreenSize():getX() -- if landscape_width > screen_width then toast("portrait") elseif landscape_width == screen_width then toast("landscape") else toast("error") end wait(2) end
|
|