Jump to content

Troubleshooting How to Find an Image and Click It


Recommended Posts

Hello friends!

I am trying to learn how to launch an application inside of Bluestacks, and android emulator. Here is the ultimate goal of my project:

  1. Launch the bluestacks program -- DONE
  2. Launch the 7 Wonders Scoring Sheet application from within bluestacks. This is my current problem, and I believe it will require an image search..
  3. Click on various tabs 'Players, military, money, wonder, etc.' This will also require an image search.
  4. Read data from those tabs.
  5. Export data to excel or a .txt document.

So, I need to find the image of the application within the bluestacks program; then to click that image. To do that I'm trying to use ImageSearch from here:

 

 

The android application I am using is a 7 Wonders Scoring Card. My friends and I use it to keep track of our board games, who wins, what score, how their economy vs. military vs. etc...
https://play.google.com/store/apps/details?id=com.aceanuu.swss&hl=en

 

Here is my current code:

#include <ScreenCapture.au3>
#include <ImageSearch.au3>

$AndroidPID = Run ("C:\ProgramData\BlueStacksGameManager\BlueStacks.exe")

Sleep(250)

$AndroidHWND = WinGetHandle("[ACTIVE]")

$AndroidPos = WinGetPos($AndroidHWND) ;--> [0] = X pos, [1] = Y pos; [2] = Width; [3] = Height

$x = 0
$y = 0

$found = _ImageSearchArea("FindMe.bmp", 1, $AndroidPos[0], $AndroidPos[1], $AndroidPos[2], $AndroidPos[3], $x, $y, 100)

If $found = 1 Then
    MouseMove($x,$y, 10)
EndIf

MsgBox (0, '', $found)
;--> Returns 0

MsgBox(0, '', $AndroidPos[0] & @CRLF & $AndroidPos[1] & @CRLF & $AndroidPos[2] & @CRLF &  $AndroidPos[3])
;--> Returns 0, 0, 1602, 950

It seems not to find the image at all. I am very confused. Perhaps it's because I'm using two monitors? However, I don't believe that's really why.

Thank you!

Adam

Link to comment
Share on other sites

i would highly suggest using a screenshot and converting it to a hBitmap then searching the hBitmap in memory. I'm not currently using the image search library but the updated version allows this.

 

heres a quick example of how i have been using screen captures and how it works in general

 

_GDIPlus_Startup()
$hBitmap = _ScreenCapture_Capture("")   ;grabs screenshot
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap);converts from bitmap to hBitmap

    
    $iX = _GDIPlus_ImageGetWidth($hImage)       ;just gets the size
    $iY = _GDIPlus_ImageGetHeight($hImage)
    $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF08INDEXED)  ;makes a copy and converts it, dumbs it down , i find this makes it 
    ;easier for searching functions to find specific things this step may not be necessary but the $GDIP_ect has a few different settings that can be 
    ;around with obviously the settings here would have to be the same as whatever bitmap your comparing it to in the image search function
    
    ;this is where youd use  _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0)


    
    ; Save bitmap to file
;~     _GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "\GDIPlus_Image.bmp")

    ; Clean up resources
    _GDIPlus_ImageDispose($hClone)
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap)

    ; Shut down GDI+ library


;~     ShellExecute(@MyDocumentsDir & "\GDIPlus_Image.bmp")
_GDIPlus_Shutdown()

 

Edited by markyrocks
Link to comment
Share on other sites

I am having inconsistencies in the script actually finding the image of the 7 wonders scoring sheet application. Sometimes it does not find the image at all, when it is clearly there. Does anybody know how I can launch an application via Shell or ADB or something like that?

 

Thanks,

astranberg

 

P.S. @Jos misunderstood my new post. He closed it down w/o explanation and refused to talk to me (he left my PM without replying). My new thread is about the exact same thing as this thread that he approved, except that it's asking to achieve the same goal in a different way. If you choose to close down this thread, please offer an explanation and a means for me to communicate with you or another moderator on the issue. Thank you.

 

 

Link to comment
Share on other sites

  • Developers
On 4/8/2016 at 8:11 PM, astranberg said:

P.S. @Jos misunderstood my new post. He closed it down w/o explanation and refused to talk to me (he left my PM without replying). My new thread is about the exact same thing as this thread that he approved, except that it's asking to achieve the same goal in a different way. If you choose to close down this thread, please offer an explanation and a means for me to communicate with you or another moderator on the issue. Thank you.

Seriously?  I don't have to do anything more than done already, so no need for sob stories here. 
I am quite responsive in general but not when I told you already not to PM me.  Can't be much clearer than that and will not go into a debate here or in PM.
This is the last time I reply to one of these type of comments and the next time will indeed simply close the thread as I am not going to be played with.

Jos
 

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I feel like PM would be a more appropriate place for this conversation. Since you will not accept those from me, and since I must have my voice heard, I am forced to reply here.

Heres what has happened:

  1. I opened a thread about a general question.
  2. I later specified it would be to automate a game.
  3. You rightfully closed the thread.
  4. I PMed you, and we cleared things up. You allowed me to post a thread still on android emulation, but this time not a game.
  5. I then created another thread about solving the same issue, except by a different means (first thread via image search, new one via ADB and shell).
  6. You closed that thread, told me it was 'sad' (or something to that effect), and told me to not PM you this time.
  7. I made my concerns known on this thread, including that you gave no reason for closure of the latter thread.
  8. You replied here saying that you would not take another reply from me, and still not offering an explanation.

Rules are rules, and if you point to a rule that says "usernames that start with an 'a' may not post new threads, then so be it. I am fine with rules. I love rules; they give structure. But another thing I love is open communication.

I am quite serious that I would like this issue resolved. I would like for other mods/admins to get involved. I understand this moderator is your own, and other moderators/admins are likely to side with him based on his position. But please, take my concerns openly. I don't really care about my thread here any more since another forum solved it for me, but the moderation displayed here is bugging me, and I would like to have a conversation about it.

I respect your position here @Jos, thank you for the work you put in here. However, I would like better communication.

Thank you. Respectfully,

astranberg

Link to comment
Share on other sites

This issue between @Jos and I has been respectfully resolved via PM.

Also, my OP question has been resolved, and this thread may be marked as 'solved.' Here is what I'm using:

SendAdb("shell am start -n com.aceanuu.swss/.MainActivity")

Func SendADB($command)
    ShellExecute("C:\Program Files (x86)\BlueStacks\HD-Adb.exe", "-s emulator-5554 "&$command)
EndFunc

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...