Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <Windows.h>
- void leftclick();
- int main()
- {
- LPCWSTR window_title = L"SM-G920F";
- HWND hWND = FindWindow(NULL, window_title);
- while (hWND == NULL) {
- hWND = FindWindow(NULL, window_title);
- std::cout<<"No window detected."<<std::endl;
- }
- while (true) {
- Sleep(10);
- if (GetAsyncKeyState(VK_UP)) {
- leftclick();
- }
- if (GetAsyncKeyState('C')) {
- HDC hDC = GetDC(hWND);
- POINT p;
- GetCursorPos(&p);
- ScreenToClient(hWND, &p);
- std::cout << "X= " << p.x << " Y= " << p.y << std::endl;
- COLORREF color1 = GetPixel(hDC, 1240, 475); //find yourself the correct x and y
- //std::cout << color1 << std::endl;
- std::cout << "Red1: "<< (int)GetRValue(color1) << std::endl;
- COLORREF color2 = GetPixel(hDC, 1320, 475);//find yourself the correct x and y
- //std::cout << color2 << std::endl;
- std::cout << "Red2: " << (int)GetRValue(color2) << std::endl;
- if ((int)GetRValue(color1)>=250 || (int)GetRValue(color2) >=250) leftclick();
- ReleaseDC(hWND, hDC);
- }
- if (GetAsyncKeyState('Q')) return 0;
- }
- }
- void leftclick() {
- std::cout << "Clicked!" << std::endl;
- INPUT iNPUT = { 0 };
- iNPUT.type = INPUT_MOUSE;
- iNPUT.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
- iNPUT.mi.mouseData =
- SendInput(1, &iNPUT, sizeof(iNPUT));
- ZeroMemory(&iNPUT, sizeof(iNPUT));
- iNPUT.type = INPUT_MOUSE;
- iNPUT.mi.dwFlags = MOUSEEVENTF_LEFTUP;
- SendInput(1, &iNPUT, sizeof(iNPUT));
- Sleep(120);
- }
Add Comment
Please, Sign In to add comment