Hey habe a bissl an einem Pixelbot gecoded, der funktioniert auch soweit nur er scheint nie den Pixel zu finden, obwohl er da ist. Kann mal jemand bitte nachschauen ob ich was übersehen habe?
main.cpp
functions.cpp
functions.h
Sorry falls der Code ineffizient ist. Lerne C++ aktiv erst seit ca. 3 Tagen :|.
main.cpp
Code:
#include <iostream>
#include <windows.h>
#include "functions.h"
using namespace std;
int main()
{
COLORREF Color = RGB(255,51,225); //Pixel
POINT CursorPos[1];
POINT Target;
HDC Handle = GetDC(NULL);
RECT Area;
BOOL StartRetrieved = false;
BOOL EndRetrieved = false;
while(1)
{
Sleep(1);
if(GetAsyncKeyState(VK_F1))
{
cout << "Retrieving Coordinates..." << endl;
while(!StartRetrieved)
{
if(GetAsyncKeyState('S'))
{
GetCursorPos(&CursorPos[0]);
cout << "Start Position saved!" << endl;
cout << CursorPos[0].x << endl << CursorPos[0].y << endl;
StartRetrieved = true;
break;
}
}
while(!EndRetrieved)
{
if(GetAsyncKeyState('E'))
{
GetCursorPos(&CursorPos[1]);
cout << "End Position saved!" << endl;
cout << CursorPos[1].x << endl << CursorPos[1].y << endl;
EndRetrieved = true;
break;
}
}
Area = CreateRECT(Handle, CursorPos[0], CursorPos[1]);
cout << "Area saved!" << endl;
cout << Area.top << endl << Area.bottom << endl << Area.left << endl << Area.right << endl;
}
if(StartRetrieved && EndRetrieved)
{
cout << "Scanning" << endl;
while(1)
{
if(GetPixelPos(Handle, Area, Color, &Target))
{
cout << "Found!" << endl;
SetCursorPos(Target.x, Target.y);
MouseClick(Handle, Target);
}
else if(GetAsyncKeyState(VK_F2))
return 0;
cout << "Not found!" << endl;
}
}
}
return 0;
}
Code:
#include <windows.h>
bool GetPixelPos(HDC Handle, RECT Area, COLORREF Color, POINT *PixelPos)
{
COLORREF Pixel;
for(int y = Area.top;y<=Area.bottom;y++)
{
for(int x = Area.left;x<=Area.right;x++)
{
Pixel = GetPixel(Handle, x, y);
if(Pixel == Color)
{
POINT PixelPos;
PixelPos.x = x;
PixelPos.y = y;
return 1;
}
}
}
return 0;
}
RECT CreateRECT(HDC Handle, POINT Start, POINT End)
{
if(End.x>Start.x)
{
RECT RECT;
RECT.left = Start.x;
RECT.top = Start.y;
RECT.right = End.x;
RECT.bottom = End.y;
return RECT;
}
else
{
RECT RECT;
RECT.left = End.x;
RECT.top = End.y;
RECT.right = Start.x;
RECT.bottom = Start.y;
return RECT;
}
}
void MouseClick(HDC Handle, POINT Position)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, Position.x, Position.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, Position.x, Position.y, 0, 0);
}
Code:
bool GetPixelPos(HDC Handle, RECT Area, COLORREF Color, POINT *PixelPos); RECT CreateRECT(HDC Handle, POINT Start, POINT End); void MouseClick(HDC Handle, POINT Position);