自动锁luogu程序源代码

版权声明:victor https://blog.csdn.net/qq_40155097/article/details/83413086

自动锁luogu程序源代码

#pragma once
#include <windows.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <conio.h>
using namespace std;
double wtime=0.0000;
inline void swap(char &a,char &b) {char t=a;a=b;b=t;}
void lock(int uid)
{
    char cmd[2100]="start https://luogu.org/login/lock?uid=";
    char st[210];int len=0;
    while(uid>0)
    {
        st[++len]=(uid%10)+'0';
        uid/=10;
    }
    for(int i=1;i<=len/2+1;i++) swap(st[i],st[len-i+1]);
    strcat(cmd,st+1);
    printf("%s\n",cmd);
    system(cmd);
}
void help()
{
    printf("/***********************************\n");
    printf("Author:https://blog.csdn.net/qq_40155097\n");
    printf("此程序将会在鼠标、键盘没有移动一段时间后自动锁定洛谷。\n");
    printf("直到再次按下键盘/移动鼠标后才重新判断鼠标、键盘状态。\n");
    printf("***********************************/\n");
}
#define clock (double)clock()/CLOCKS_PER_SEC
bool bj(POINT a,POINT b) {return a.x!=b.x || a.y!=b.y;}
int main()
{
    help();
    printf("请输入User ID:");
    int uid;scanf("%d",&uid);
    printf("请输入等待时间(浮点数,sec):");
    scanf("%lf",&wtime);
    printf("是否要隐藏此窗口? (Y/n)");
    char hh=getche();
    printf("\n");
    if(hh=='y' || hh=='Y')
    {
        HWND hwnd=::GetForegroundWindow();
        MoveWindow(hwnd,0,0,0,0,true);
    }
    while(1)
    {
        while(1)
        {
            double st=clock;
            bool bk=true;
            POINT cst;GetCursorPos(&cst);
            while(clock-st<=wtime)
            {
                if(kbhit()) {bk=false;break;}
                POINT hh;GetCursorPos(&hh);
                if(bj(hh,cst)) {bk=false;break;}
            }
            if(bk==true)
            {
                lock(uid);
                break;
            }
        }
        POINT cst;GetCursorPos(&cst);
        while(1)
        {
            if(kbhit()) break;
            POINT hh;GetCursorPos(&hh);
            if(bj(hh,cst)) break;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40155097/article/details/83413086