C + + self created nail live brush

Posted by MikeDXUNL on Fri, 21 Feb 2020 16:04:33 +0100

Last time, the nail brush was really popular, maybe because of the special period

But this program is still insufficient!!

At the strong request of my friend, I added the half way cancellation function.
Source code:

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <cmath>
#include <iostream>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)& 0x8000 ?1:0))
using namespace std;
void SetSize(unsigned uCol,unsigned uLine)
{
 char cmd[64];
 sprintf(cmd,"mode con cols=%d lines=%d",uCol,uLine);
 system(cmd);
}
template <typename _T>
_T pow2(_T x)
{
    return x * x;
}
DOUBLE Distance(POINT &a,POINT &b) //Distance between two points 
{
 return sqrt(pow2(a.x - b.x) + pow2(a.y - b.y));
}
VOID KeyPR(BYTE bVk) { //Press && Release
 keybd_event(bVk,0,0,0);
 keybd_event(bVk,0,2,0);
}
VOID Click()
{
 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
int main()
{
    int i=0;
 int n=100;  //frequency 
 int speed=64; //Praise per second 
 int ch;
 bool bAgain=false;
POINT pt,pt2; //Mouse coordinates 
LONG maxDsc=40; //Mouse offset limit distance 
 SetConsoleTitle("Nail brush");
 SetSize(35,20); 
 while(true)
 {
 ch=IDOK; //Don't bother to use do while
 while(FindWindow("StandardFrame",NULL) == NULL && ch == IDOK){
  ch = MessageBox(GetConsoleWindow(),"The live nailing window is not opened.\n Please open it and press OK.","Tips",MB_ICONEXCLAMATION|MB_OKCANCEL);
 }
 if(ch == IDCANCEL || ch == IDCLOSE)
 {
  cout<<"Cancelled...";
  Sleep(500);
  exit(0);
 }
 do
 {
  cout<<"Enter likes per second(1~1000): ";
  cin>>speed;
  if(speed < 1 || speed > 1000){
     cout<<"\n Non conformance scope(1~1000)!\n";
        }
 }while(speed < 1 || speed > 1000);
 do
 {
  cout<<"\n Input times:";
  cin>>n;
  if(n < 0){
     cout<<"\n Non conformance scope(>0)!\n";
        }
 }while(n < 0);
 cout<<"\n\n Ready.\n Hide this window now, a few seconds later\n Please click like to start swiping like...\n";
 Sleep(3000);
 ShowWindow(GetConsoleWindow(),SW_HIDE);
 if(FindWindow("Msgbox",NULL) != NULL)
     KeyPR(VK_SPACE);
 Sleep(1000);
 while(!KEY_DOWN(MOUSE_MOVED));
GetCursorPos(&pt);
  do{
   if(FindWindow("Msgbox",NULL) == NULL)
      Click();
        else
      KeyPR(VK_SPACE);
   Sleep((DWORD)1000.0 / speed);
   i++;
   if(i % speed == 0) //Detect mouse once per second 
        {
         GetCursorPos(&pt2); //Take another time. 
         if(Distance(pt,pt2) > maxDsc)
    { //Provisional cancellation
   //Do not jump out of the console, directly exit, so safe. )
    exit(-1); 
    } 
  }
  }while(i <= n);
  Sleep(1000);
  if(FindWindow("Msgbox",NULL) != NULL)
     KeyPR(VK_SPACE);
     ShowWindow(GetConsoleWindow(),SW_SHOW);
     cout<<"\n Success!\n Whether to continue?(Press 1:yes/0:no) ";
     int ch2;
     againp:
     ch2=getch();
     switch(ch2)
     {
      case '1':
   bAgain=true;
   cout<<endl;
   system("cls");
   break;
      case '0':
   bAgain=false;
   break;
      default:
   goto againp;
   break;
  }
  
     }while(bAgain);
  return 0;
} 

I added the coordinates of the mouse to calculate the difference, and 40 px is the best value after debugging
Cancellation method:
Very simple, don't want to brush the mouse a hard move on the line.

(warning: do not move to the left, do not press the "apply for wheat" button!!!! )

Published 10 original articles, won praise 3, visited 2371
Private letter follow

Topics: Windows