Mouse Click on image

General discussion about the Phantom Automation Language and related tools.

Mouse Click on image

Postby Voron on Thu May 13, 2010 9:24 am

Hello everyone :) Im trying to do simple automation and im wondering if its possible to use these function :
Code: Select all
window.MouseClick(int iButton, int ix, int iy, int iType);
but replace ix,iy by an image. So it will click on image not on certain coordinates, since image position is constantly changing. It should work like these : Search for an image on screen and click on it. Thanks in advance for all answers :)
Voron
 
Posts: 1
Joined: Thu May 13, 2010 9:20 am

Re: Mouse Click on image

Postby john on Tue May 18, 2010 12:41 pm

Hello-

If you know what the image is ahead of time, you can use Phantom's bitmap functions to find an image and then click on it. I have included some sample code below to do this:

Code: Select all
# Before running this, open the Phantom Target application, then:
# 1. Check Options->MessageBox->Controls (to verify the mouse click)
# 2. Select Controls->PushButton

# Uncomment to create the search bitmap
#bitmap b = MainWin("Button Dialog", "#32770").MainWin("GBUTTON", "Button").CaptureBitmap();
#b.Save("search.bmp");
#return;

# Function to click on an image
function void ClickImage(window w, bitmap b){
        # Capture the bitmap of the target window
   bitmap temp = w.CaptureBitmap();

   # Get the height of the target window bitmap
   int wH = temp.GetHeight();
   
   # Get dimensions of the search bitmap
   int bH = b.GetHeight();
   int bW = b.GetWidth();
   
   # Variables to hold the X, Y location of the bitmap
   int X;
   int Y;
   
   # Search the window bitmap for the desired bitmap
   if(temp.Find(X, Y, b)){
           # Click on the center of the bitmap if found
      w.MouseClick(0,X+bW/2,wH-(Y+bH/2),0);
      disp("Image found and clicked");
   }else{
           # Throw an error if not found
      exception e;
      e.SetError("Could not find image");
      e.throw();      
   }
}

# An example of how to use ClickImage:
bitmap bSearch;
bSearch.Load("search.bmp");

window wSearch = MainWin("Button Dialog", "#32770");
ClickImage(wSearch, bSearch);


This code finds a bitmap in the Phantom Target application PushButton window, and then clicks the center of the bitmap. A message should appear from the Phantom Target saying the button was clicked. You should be able to copy and paste the function directly into your script. Note that, if possible, you should use Phantom to capture the bitmap ahead of time to ensure it is in the correct format. The help documentation has more information on using bitmaps.

I hope this helps!

-John
john
 
Posts: 27
Joined: Wed Apr 22, 2009 12:32 pm


Return to Phantom

Who is online

Users browsing this forum: No registered users and 5 guests

cron