Как я создавал автокликер для приложения «ДругВокруг»02.01.2024 15:45
#include
#include
#include
using namespace std;
/*#ifndef CAPTUREBLT
#define CAPTUREBLT (DWORD)0x40000000 /* Include layered windows */
#define CAPTUREBLT 0x40000000
//#define CLICK mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);Sleep(5);mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0)
/*inline void init(){
HWND dvkr = FindWindow(NULL,"ДругВокруг");
RECT crd;
GetWindowRect(dvkr,&crd);
}*/
inline void moveclick(int x, int y){
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Sleep(5);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
inline void telclear(){
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(VK_BACK, 0, 0, 0);
Sleep(5);
keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
}
void txtpaste(char* text, RECT crd){
if(OpenClipboard(0)){
EmptyClipboard();
char* clip_data = (char*)(GlobalAlloc(GMEM_FIXED, MAX_PATH));
lstrcpy(clip_data, text);
SetClipboardData(CF_TEXT, (HANDLE)(clip_data));
LCID* lcid = (DWORD*)(GlobalAlloc(GMEM_FIXED, sizeof(DWORD)));
*lcid = MAKELCID(MAKELANGID(LANG_RUSSIAN, SUBLANG_NEUTRAL), SORT_DEFAULT);
SetClipboardData(CF_LOCALE, (HANDLE)(lcid));
CloseClipboard();
}
//В новом интерфейсе запретили комбинацию "CTRL+V";
//Отказывается путём работать "SHIFT+INSERT";
//Но работает вставка через контекстное меню;
//keybd_event(VK_CONTROL, 0, 0, 0);
/*keybd_event(VK_LSHIFT, 0, 0, 0);
//keybd_event(0x56, 0, 0, 0);
keybd_event(VK_INSERT, 0, 0, 0);
Sleep(5);
//keybd_event(0x56, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_INSERT, 0, KEYEVENTF_KEYUP, 0);
//keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LSHIFT, 0, KEYEVENTF_KEYUP, 0);*/
SetCursorPos(crd.left+455,crd.top+118);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
Sleep(5);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
SetCursorPos(crd.left+483,crd.top+220);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Sleep(5);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
inline void find(RECT crd){
//Не работает поиск по нажатию виртуальной "ENTER" в новом интерфейсе;
//Придётся жмать мышью;
/*keybd_event(VK_RETURN, 0, 0, 0);
Sleep(5);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);*/
SetCursorPos(crd.left+420,crd.top+177);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Sleep(5);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
inline int GetFilePointer(HANDLE FileHandle){
return SetFilePointer(FileHandle, 0, 0, FILE_CURRENT);
}
bool SaveBMPFile(char *filename, HDC bitmapDC, int width, int height){
bool Success=0;
HDC SurfDC=NULL;
HBITMAP OffscrBmp=NULL;
HDC OffscrDC=NULL;
LPBITMAPINFO lpbi=NULL;
LPVOID lpvBits=NULL;
HANDLE BmpFile=INVALID_HANDLE_VALUE;
BITMAPFILEHEADER bmfh;
if ((OffscrBmp = CreateCompatibleBitmap(bitmapDC, width, height)) == NULL)
return 0;
if ((OffscrDC = CreateCompatibleDC(bitmapDC)) == NULL)
return 0;
HBITMAP OldBmp = (HBITMAP)SelectObject(OffscrDC, OffscrBmp);
BitBlt(OffscrDC, 0, 0, width, height, bitmapDC, 0, 0, SRCCOPY);
if ((lpbi = (LPBITMAPINFO)(new char[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)])) == NULL)
return 0;
ZeroMemory(&lpbi->bmiHeader, sizeof(BITMAPINFOHEADER));
lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
SelectObject(OffscrDC, OldBmp);
if (!GetDIBits(OffscrDC, OffscrBmp, 0, height, NULL, lpbi, DIB_RGB_COLORS))
return 0;
if ((lpvBits = new char[lpbi->bmiHeader.biSizeImage]) == NULL)
return 0;
if (!GetDIBits(OffscrDC, OffscrBmp, 0, height, lpvBits, lpbi, DIB_RGB_COLORS))
return 0;
if ((BmpFile = CreateFile(filename,
GENERIC_WRITE,
0, NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE)
return 0;
DWORD Written;
bmfh.bfType = 19778;
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
if (!WriteFile(BmpFile, &bmfh, sizeof(bmfh), &Written, NULL))
return 0;
if (Written < sizeof(bmfh))
return 0;
if (!WriteFile(BmpFile, &lpbi->bmiHeader, sizeof(BITMAPINFOHEADER), &Written, NULL))
return 0;
if (Written < sizeof(BITMAPINFOHEADER))
return 0;
int PalEntries;
if (lpbi->bmiHeader.biCompression == BI_BITFIELDS)
PalEntries = 3;
else PalEntries = (lpbi->bmiHeader.biBitCount <= 8) ?
(int)(1 << lpbi->bmiHeader.biBitCount) : 0;
if(lpbi->bmiHeader.biClrUsed)
PalEntries = lpbi->bmiHeader.biClrUsed;
if(PalEntries){
if (!WriteFile(BmpFile, &lpbi->bmiColors, PalEntries * sizeof(RGBQUAD), &Written, NULL))
return 0;
if (Written < PalEntries * sizeof(RGBQUAD))
return 0;
}
bmfh.bfOffBits = GetFilePointer(BmpFile);
if (!WriteFile(BmpFile, lpvBits, lpbi->bmiHeader.biSizeImage, &Written, NULL))
return 0;
if (Written < lpbi->bmiHeader.biSizeImage)
return 0;
bmfh.bfSize = GetFilePointer(BmpFile);
SetFilePointer(BmpFile, 0, 0, FILE_BEGIN);
if (!WriteFile(BmpFile, &bmfh, sizeof(bmfh), &Written, NULL))
return 0;
if (Written < sizeof(bmfh))
return 0;
return 1;
}
bool ScreenCapture(int x, int y, int width, int height, char *filename){
FILE *f;
f=fopen("1.txt","w");
HWND dvkr = FindWindow(NULL,"ДругВокруг");
RECT crd;
GetWindowRect(dvkr,&crd);
HDC hDc = CreateCompatibleDC(0);
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(dvkr), width, height);
SelectObject(hDc, hBmp);
BitBlt(hDc, 0, 0, width, height, GetDC(dvkr), x, y, SRCCOPY|CAPTUREBLT);
bool ret = SaveBMPFile(filename, hDc, width, height);
DeleteObject(hBmp);
BitBlt(hDc, 0, 0, 1, 1, GetDC(dvkr), 200, 410, SRCCOPY|CAPTUREBLT);
COLORREF clrf = GetPixel(hDc,1,1);
fprintf(f,"%X\n%i\t%i\t%i\t%i\t",clrf,crd.left,crd.top,crd.right,crd.bottom);
fclose(f);
return ret;
}
int main(){
HDC hDc;
HBITMAP hBmp;
HWND dvkr = FindWindow(NULL,"ДругВокруг - Поиск");
RECT crd;
GetWindowRect(dvkr,&crd);
COLORREF clrf;
int tel=0;
char str[14],name[14];
FILE *f;
f=fopen("Out.txt","r");
//sprintf(str,"89536158567");
//sprintf(name,"%s.bmp",str);
//sprintf(str,"89536158567");
for(tel=3000; tel<=3999; tel++){
//while(!feof(f)){
//fscanf(f,"%s\n",&str);
sprintf(str,"8953617%04i",tel);
sprintf(name,"953617%04i.bmp",tel);
//sprintf(name,"%s.bmp",str);
//moveclick(crd.left+312,crd.top+246);
moveclick(crd.left+455,crd.top+118); //Новый интерфейс;
telclear();
//moveclick(crd.left+455,crd.top+118); //Очистили, и опять кликаем;
Sleep(5);
txtpaste(str,crd);
Sleep(10);
find(crd);
Sleep(10);
do{
Sleep(300);
hDc = CreateCompatibleDC(0);
hBmp = CreateCompatibleBitmap(GetDC(dvkr), 2, 2);
SelectObject(hDc, hBmp);
DeleteObject(hBmp);
//BitBlt(hDc, 0, 0, 1, 1, GetDC(dvkr), 40, 288, SRCCOPY|CAPTUREBLT);
//BitBlt(hDc, 0, 0, 1, 1, GetDC(dvkr), 220, 168, SRCCOPY|CAPTUREBLT);
BitBlt(hDc, 0, 0, 1, 1, GetDC(dvkr), 320, 177, SRCCOPY|CAPTUREBLT);
clrf = GetPixel(hDc,0,0);
//DeleteObject(hDc);
}while(clrf==0xC8D0D4);
//}while(clrf==0xEEEDE8);
//if(clrf!=0xEDE9E4){
//if(clrf==0xC8D0D4){
if(clrf!=0xEEEDE8&&clrf!=0xFFFFFF){
return 0;
}
//HDC hDc = CreateCompatibleDC(0);
//HBITMAP hBmp = CreateCompatibleBitmap(GetDC(dvkr), 2, 2);
//SelectObject(hDc, hBmp);
//DeleteObject(hBmp);
//DeleteObject(hDc);
//BitBlt(hDc, 0, 0, 1, 1, GetDC(dvkr), 200, 410, SRCCOPY|CAPTUREBLT);
//clrf = GetPixel(hDc,0,0);
//if(clrf==0xE1E1E1){
if(clrf==0xFFFFFF){
//fprintf(f,"%s\n",str);
//moveclick(crd.left+67,crd.top+380);
moveclick(crd.left+220,crd.top+120);
Sleep(2000);
hBmp = CreateCompatibleBitmap(GetDC(dvkr), 490, 851);
SelectObject(hDc, hBmp);
BitBlt(hDc, 0, 0, 490, 851, GetDC(dvkr), 494, 30, SRCCOPY|CAPTUREBLT); //336 -> 494;
SaveBMPFile(name, hDc, 490, 851);
DeleteObject(hBmp);
DeleteObject(hDc);
//moveclick(crd.left+487,crd.top+41);
moveclick(crd.left+646,crd.top+35);
Sleep(100);
moveclick(crd.left+440,crd.top+50);
Sleep(100);
}else{
if(clrf!=0xF3F3F3){
//return 0;
}
}
//Sleep(1000);
}
//fprintf(f,"%X\n%i\t%i\t%i\t%i\n",clrf,crd.left,crd.top,crd.right,crd.bottom);
//fclose(f);
return 0;
}
© Habrahabr.ru