WINAPI.hpp
#pragma once
#include "Zinclude.hpp"
#include "Mouse.hpp"
#include "Keyboard.hpp"
#ifdef ZECSTD
using namespace std;
#endifZinclude.hpp
#if defined(__GNUC__) || defined(__GNUG__)
#include <bits/stdc++.h>
#elif defined(_MSC_VER)
#include <iostream>
#include <vector>
#include <algorithm>
#endif
#include<windows.h>Mouse.hpp
#ifndef Mouse
#include "Zinclude.hpp"
#ifndef MouseEvent
#define MouseLeftDown MOUSEEVENTF_LEFTDOWN
#define MouseLeftUp MOUSEEVENTF_LEFTUP
#define MouseRightDown MOUSEEVENTF_RIGHTDOWN
#define MouseRightUp MOUSEEVENTF_RIGHTUP
#define MouseDown mouse_event
#endif
struct MousePos
{
int x, y;
};
MousePos GetMousePos()
{
POINT p;
GetCursorPos(&p);
return {p.x, p.y};
}
void MaveMouse(int x, int y)
{
SetCursorPos(x, y);
}
#endifKeyboard
#include "Zinclude.hpp"
// 钩子
/*
安装钩子
HHOOK SetWindowsHookEx(
int idHook, // 钩子类型
HOOKPROC lpfn, // 钩子过程函数
HINSTANCE hMod, // 包含钩子过程的DLL句柄
DWORD dwThreadId // 线程ID (0表示全局钩子)
);
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
UnhookWindowsHookEx - 卸载钩子
BOOL
UnhookWindowsHookEx(
HHOOK hhk // 要卸载的钩子句柄
);
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
CallNextHookEx - 传递钩子
LRESULT
CallNextHookEx(
HHOOK hhk, // 当前钩子句柄
int nCode, // 钩子代码
WPARAM wParam, // 消息参数
LPARAM lParam // 消息参数
);
*/
/*
VK_LBUTTON // 鼠标左键 (0x01)
VK_RBUTTON // 鼠标右键 (0x02)
VK_MBUTTON // 鼠标中键 (0x04)
VK_BACK // Backspace 键 (0x08)
VK_TAB // Tab 键 (0x09)
VK_RETURN // Enter 键 (0x0D)
VK_SHIFT // Shift 键 (0x10)
VK_CONTROL // Ctrl 键 (0x11)
VK_MENU // Alt 键 (0x12)
VK_ESCAPE // ESC 键 (0x1B)
VK_SPACE // 空格键 (0x20)
VK_LEFT // 左箭头 (0x25)
VK_UP // 上箭头 (0x26)
VK_RIGHT // 右箭头 (0x27)
VK_DOWN // 下箭头 (0x28)
'0'-'9' // 数字键 (0x30-0x39)
'A'-'Z' // 字母键 (0x41-0x5A)
*/
#define DOWNING 0x8000
#define DOWNED 0x0001
#define IsKeyDown GetAsyncKeyState连点器
#include "WINAPI.hpp"
using namespace std;
int main()
{
bool x;
cout << "1:Left,0:Right:\n";
cin >> x;
if (x)
{
while (true)
{
if(IsKeyDown(VK_ESCAPE)&DOWNED){
return 0;
}
MousePos Now = GetMousePos();
int x = Now.x, y = Now.y;
mouse_event(MouseLeftDown, x, y, 0, 0);
mouse_event(MouseLeftUp, x, y, 0, 0);
}
}
else
{
while (true)
{
if(IsKeyDown(VK_ESCAPE)&DOWNED){
return 0;
}
MousePos Now = GetMousePos();
int x = Now.x, y = Now.y;
mouse_event(MouseRightDown, x, y, 0, 0);
mouse_event(MouseRightUp, x, y, 0, 0);
}
}
return 0;
}