:lol:Hi everyone,
I'm am trying to make an auto clicker for an online game using delphi. The only way I can think of doing it is by searching the screen for a particular color and then clicking on it. I'm finding this difficult to do.
The program should find a color(monster) and then click it. I can automate the clicking and the mouse movement but I still have no way to find the color(monster) x,y
Any help or ideas would be great
Thanks in advance.
3 replies to this topic
#1
Posted 15 April 2011 - 04:10 PM
|
|
|
#2
Posted 15 April 2011 - 05:40 PM
I'd look to do this in AutoIt, rather coding this in Delphi from scratch.
#3
Posted 17 April 2011 - 02:04 PM
I never done things like this with online application before. But if it's me, I would check capabilities provided by TWebBrowser (i.e. embedded IE), check MSDN to see if IE has features you can use, then use it via TWebBrowser.
#4
Posted 22 April 2011 - 07:46 AM
To click on a certain color you first need to define the color then search for it. To get the color use the GetPixel API. Since you seem to have no problems moving the cursor and simulating a click I won’t try and explain it. The code below will display the pixel color at the cursor location and display it. I converted the TColor into its RGB values for this example.
Basically what you’ll want to do is define an area to scan; my example uses the entire desktop. Your application will need to use the the area in the browser that contains the “game”. Start at the top left and scan to the bottom looking for a specific color. When your color is found move the cursor there and simulate the click then exit the function.
To run the code below, add three labels and a timer to a form. The labels will display the RGB values of the desktop location.
Hope that helps.
EDIT: That code, although sound, is too slow for your purpose. I decided to try it out :thumbdown:. Instead use the scanline command, about 300 times faster. An example of testing for an RGB value in an image below.
Code using GetPixel API...
Code using Scanline...
Basically what you’ll want to do is define an area to scan; my example uses the entire desktop. Your application will need to use the the area in the browser that contains the “game”. Start at the top left and scan to the bottom looking for a specific color. When your color is found move the cursor there and simulate the click then exit the function.
To run the code below, add three labels and a timer to a form. The labels will display the RGB values of the desktop location.
Hope that helps.
EDIT: That code, although sound, is too slow for your purpose. I decided to try it out :thumbdown:. Instead use the scanline command, about 300 times faster. An example of testing for an RGB value in an image below.
Code using GetPixel API...
function GetColor(const X, Y: Integer): TColor; var TmpCanvas: TCanvas; begin TmpCanvas := TCanvas.Create; try TmpCanvas.Handle := GetWindowDC(GetDesktopWindow); Result := GetPixel(TmpCanvas.Handle, X, Y); finally TmpCanvas.Free; end; end; procedure TForm1.Timer1Timer(Sender: TObject); var Pos: TPoint; Red, Green, Blue: Integer; PixelColor: Longint; MyColor: TColor; begin // Get the pixel color at the cursor location GetCursorPos(Pos); MyColor := GetColor(Pos.X, Pos.Y); // Convert the pixel color to its RGB components PixelColor := ColorToRGB(Canvas.Pixels[Pos.X, Pos.Y]); Red := MyColor and $ff; Green := (MyColor and $ff00) shr 8; Blue := (MyColor and $ff0000) shr 16; //Display the RGB values Label1.Caption := 'Red: ' + IntToStr(Red); Label2.Caption := 'Green: ' + IntToStr(Green); Label3.Caption := 'Blue: ' + IntToStr(Blue); end;
Code using Scanline...
procedure TForm1.Button1Click(Sender: TObject);
type
TRGBTripleArray = ARRAY[Word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
x,y : Integer;
MyBitMap: TBitMap;
PicArray: pRGBTripleArray;
Format: TPixelFormat;
begin
MyBitMap := TBitMap.create;
try
// Here you will need to capture the area as a bitmap and assign it rather than loading as a file.
// If using a TWebBrowser there are more efficient ways to capture the document as an image, just
// google for many examples.
MyBitMap.LoadFromFile('RGB.bmp');
Format := MyBitMap.PixelFormat;
MyBitMap.PixelFormat := pf24bit;
for y := 0 to MyBitMap.Height - 1 do
begin
PicArray := MyBitMap.ScanLine[y];
for x := 0 to MyBitMap.Width - 1 do
begin
// Check for any color desired using RGB values
if (PicArray[x].rgbtBlue = 255) and (PicArray[X].rgbtGreen = 0) and (PicArray[X].rgbtRed = 0) then
begin
ShowMessage('Blue found at: X:' + IntToStr(X) + ' Y:' + IntToSTr(Y));
// Move the mouse to X,Y and simulate the click
MyBitMap.Free;
exit;
end;
end;
end;
finally
MyBitMap.Free;
end;
end;
Edited by Zorfox, 22 April 2011 - 02:25 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









