(C++小白的作品,别在意~)
头文件1(键盘)(MKeyBoard.hxx)
#ifndef _GLIBCXX_MKEYBOARD
#define _GLIBCXX_MKEYBOARD 1
#pragma GCC system_header
#include <windows.h>
#include <cstring>
#include <string>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
namespace std
{
namespace MKeyBoard
{
// empty
#define MKB 0
#define MKB_ 0
// letter
#define MKB_A 65
#define MKB_B 66
#define MKB_C 67
#define MKB_D 68
#define MKB_E 69
#define MKB_F 70
#define MKB_G 71
#define MKB_H 72
#define MKB_I 73
#define MKB_J 74
#define MKB_K 75
#define MKB_L 76
#define MKB_M 77
#define MKB_N 78
#define MKB_O 79
#define MKB_P 80
#define MKB_Q 81
#define MKB_R 82
#define MKB_S 83
#define MKB_T 84
#define MKB_U 85
#define MKB_V 86
#define MKB_W 87
#define MKB_X 88
#define MKB_Y 89
#define MKB_Z 90
// number
#define MKB_0 48
#define MKB_1 49
#define MKB_2 50
#define MKB_3 51
#define MKB_4 52
#define MKB_5 53
#define MKB_6 54
#define MKB_7 55
#define MKB_8 56
#define MKB_9 57
// symbol
#define MKB_Comma 188
#define MKB_Dot 190
#define MKB_Slash 191
#define MKB_Semicolon 186
#define MKB_SingleQuotationMarks 222
#define MKB_OpenBracket 219
#define MKB_CloseBracket 221
#define MKB_Minus 189
#define MKB_Equal 187
#define MKB_BackSlash 220
#define MKB_Plus0 107
#define MKB_Minus0 109
#define MKB_IsMultipliedBy0 106
#define MKB_IsDividedBy0 111
#define MKB_Dot0 110
// shortcut
#define MKB_F1 112
#define MKB_F2 113
#define MKB_F3 114
#define MKB_F4 115
#define MKB_F5 116
#define MKB_F6 117
#define MKB_F7 118
#define MKB_F8 119
#define MKB_F9 120
#define MKB_F10 121
#define MKB_F11 122
#define MKB_F12 123
// direction
#define MKB_Left 37
#define MKB_Up 38
#define MKB_Right 39
#define MKB_Down 40
// other
#define MKB_Enter 13
#define MKB_CapsLook 20
#define MKB_Shift 16
#define MKB_Tap 9
#define MKB_BackSpace 8
#define MKB_Ctrl 17
#define MKB_Win 91
#define MKB_Alt 18
#define MKB_Space 32
#define MKB_Delete 46
class KeyBoardIn
{
private:
bool ist;
public:
KeyBoardIn()
{
ist = true;
}
KeyBoardIn(bool _ist)
{
ist = _ist;
}
bool KeyIsDown(int a)
{
return KEY_DOWN(a);
}
bool CapsIsUp()
{
return GetKeyState(MKB_CapsLook);
}
bool IsFalse()
{
return !ist;
}
bool Clear()
{
ist = true;
}
operator bool()
{
return ist;
}
KeyBoardIn operator>>(char& a)
{
if (!ist)
{
return false;
}
while (true)
{
if (KeyIsDown(MKB_Ctrl)&& KeyIsDown(MKB_Z))
{
return false;
}
else if (KeyIsDown(MKB_A))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'a';
return *this;
}
else
{
a = 'A';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'A';
return *this;
}
else
{
a = 'a';
return *this;
}
}
}
else if (KeyIsDown(MKB_B))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'b';
return *this;
}
else
{
a = 'B';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'B';
return *this;
}
else
{
a = 'b';
return *this;
}
}
}
else if (KeyIsDown(MKB_C))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'c';
return *this;
}
else
{
a = 'C';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'C';
return *this;
}
else
{
a = 'c';
return *this;
}
}
}
else if (KeyIsDown(MKB_D))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'd';
return *this;
}
else
{
a = 'D';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'D';
return *this;
}
else
{
a = 'd';
return *this;
}
}
}
else if (KeyIsDown(MKB_E))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'e';
return *this;
}
else
{
a = 'E';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'E';
return *this;
}
else
{
a = 'e';
return *this;
}
}
}
else if (KeyIsDown(MKB_F))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'f';
return *this;
}
else
{
a = 'F';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'F';
return *this;
}
else
{
a = 'f';
return *this;
}
}
}
else if (KeyIsDown(MKB_G))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'g';
return *this;
}
else
{
a = 'G';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'G';
return *this;
}
else
{
a = 'g';
return *this;
}
}
}
else if (KeyIsDown(MKB_H))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'h';
return *this;
}
else
{
a = 'H';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'H';
return *this;
}
else
{
a = 'h';
return *this;
}
}
}
else if (KeyIsDown(MKB_I))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'i';
return *this;
}
else
{
a = 'I';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'I';
return *this;
}
else
{
a = 'i';
return *this;
}
}
}
else if (KeyIsDown(MKB_J))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'j';
return *this;
}
else
{
a = 'J';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'J';
return *this;
}
else
{
a = 'j';
return *this;
}
}
}
else if (KeyIsDown(MKB_K))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'k';
return *this;
}
else
{
a = 'K';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'K';
return *this;
}
else
{
a = 'k';
return *this;
}
}
}
else if (KeyIsDown(MKB_L))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'l';
return *this;
}
else
{
a = 'L';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'L';
return *this;
}
else
{
a = 'l';
return *this;
}
}
}
else if (KeyIsDown(MKB_M))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'm';
return *this;
}
else
{
a = 'M';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'M';
return *this;
}
else
{
a = 'm';
return *this;
}
}
}
else if (KeyIsDown(MKB_N))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'n';
return *this;
}
else
{
a = 'N';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'N';
return *this;
}
else
{
a = 'n';
return *this;
}
}
}
else if (KeyIsDown(MKB_O))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'o';
return *this;
}
else
{
a = 'O';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'O';
return *this;
}
else
{
a = 'o';
return *this;
}
}
}
else if (KeyIsDown(MKB_P))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'p';
return *this;
}
else
{
a = 'P';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'P';
return *this;
}
else
{
a = 'p';
return *this;
}
}
}
else if (KeyIsDown(MKB_R))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'r';
return *this;
}
else
{
a = 'R';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'R';
return *this;
}
else
{
a = 'r';
return *this;
}
}
}
else if (KeyIsDown(MKB_S))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 's';
return *this;
}
else
{
a = 'S';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'T';
return *this;
}
else
{
a = 't';
return *this;
}
}
}
else if (KeyIsDown(MKB_U))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'u';
return *this;
}
else
{
a = 'U';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'U';
return *this;
}
else
{
a = 'u';
return *this;
}
}
}
else if (KeyIsDown(MKB_V))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'v';
return *this;
}
else
{
a = 'V';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'V';
return *this;
}
else
{
a = 'v';
return *this;
}
}
}
else if (KeyIsDown(MKB_W))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'w';
return *this;
}
else
{
a = 'W';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'W';
return *this;
}
else
{
a = 'w';
return *this;
}
}
}
else if (KeyIsDown(MKB_X))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'x';
return *this;
}
else
{
a = 'X';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'X';
return *this;
}
else
{
a = 'x';
return *this;
}
}
}
else if (KeyIsDown(MKB_Y))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'y';
return *this;
}
else
{
a = 'Y';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'Y';
return *this;
}
else
{
a = 'y';
return *this;
}
}
}
else if (KeyIsDown(MKB_Z))
{
if (CapsIsUp())
{
if (KeyIsDown(MKB_Shift))
{
a = 'z';
return *this;
}
else
{
a = 'Z';
return *this;
}
}
else
{
if (KeyIsDown(MKB_Shift))
{
a = 'Z';
return *this;
}
else
{
a = 'z';
return *this;
}
}
}
else if (KeyIsDown(MKB_1))
{
if (KeyIsDown(MKB_Shift))
{
a = '!';
return *this;
}
else
{
a = '1';
return *this;
}
}
else if (KeyIsDown(MKB_2))
{
if (KeyIsDown(MKB_Shift))
{
a = '@';
return *this;
}
else
{
a = '2';
return *this;
}
}
else if (KeyIsDown(MKB_3))
{
if (KeyIsDown(MKB_Shift))
{
a = '#';
return *this;
}
else
{
a = '3';
return *this;
}
}
else if (KeyIsDown(MKB_4))
{
if (KeyIsDown(MKB_Shift))
{
a = '$';
return *this;
}
else
{
a = '4';
return *this;
}
}
else if (KeyIsDown(MKB_5))
{
if (KeyIsDown(MKB_Shift))
{
a = '%';
return *this;
}
else
{
a = '5';
return *this;
}
}
else if (KeyIsDown(MKB_6))
{
if (KeyIsDown(MKB_Shift))
{
a = '^';
return *this;
}
else
{
a = '6';
return *this;
}
}
else if (KeyIsDown(MKB_7))
{
if (KeyIsDown(MKB_Shift))
{
a = '&';
return *this;
}
else
{
a = '7';
return *this;
}
}
else if (KeyIsDown(MKB_8))
{
if (KeyIsDown(MKB_Shift))
{
a = '*';
return *this;
}
else
{
a = '8';
return *this;
}
}
else if (KeyIsDown(MKB_9))
{
if (KeyIsDown(MKB_Shift))
{
a = '(';
return *this;
}
else
{
a = '9';
return *this;
}
}
else if (KeyIsDown(MKB_0))
{
if (KeyIsDown(MKB_Shift))
{
a = ')';
return *this;
}
else
{
a = '0';
return *this;
}
}
else if (KeyIsDown(MKB_OpenBracket))
{
if (KeyIsDown(MKB_Shift))
{
a = '{';
return *this;
}
else
{
a = '[';
return *this;
}
}
else if (KeyIsDown(MKB_CloseBracket))
{
if (KeyIsDown(MKB_Shift))
{
a = '}';
return *this;
}
else
{
a = ']';
return *this;
}
}
else if (KeyIsDown(MKB_Minus))
{
if (KeyIsDown(MKB_Shift))
{
a = '_';
return *this;
}
else
{
a = '-';
return *this;
}
}
else if (KeyIsDown(MKB_Equal))
{
if (KeyIsDown(MKB_Shift))
{
a = '+';
return *this;
}
else
{
a = '=';
return *this;
}
}
else if (KeyIsDown(MKB_BackSlash))
{
if (KeyIsDown(MKB_Shift))
{
a = '|';
return *this;
}
else
{
a = '\\';
return *this;
}
}
else if (KeyIsDown(MKB_Semicolon))
{
if (KeyIsDown(MKB_Shift))
{
a = ':';
return *this;
}
else
{
a = ';';
return *this;
}
}
else if (KeyIsDown(MKB_SingleQuotationMarks))
{
if (KeyIsDown(MKB_Shift))
{
a = '\"';
return *this;
}
else
{
a = '\'';
return *this;
}
}
else if (KeyIsDown(MKB_Comma))
{
if (KeyIsDown(MKB_Shift))
{
a = '<';
return *this;
}
else
{
a = ',';
return *this;
}
}
else if (KeyIsDown(MKB_Dot))
{
if (KeyIsDown(MKB_Shift))
{
a = '>';
return *this;
}
else
{
a = '.';
return *this;
}
}
else if (KeyIsDown(MKB_Slash))
{
if (KeyIsDown(MKB_Shift))
{
a = '?';
return *this;
}
else
{
a = '/';
return *this;
}
}
}
}
KeyBoardIn operator>>(string& a)
{
char temp;
while ((*this) >> temp)
{
if (temp == ' ' || temp == '\n')
{
return (*this);
}
a += temp;
}
return false;
}
KeyBoardIn getline(string& a)
{
while (true)
{
char temp;
(*this) >> temp;
if (temp == '\n')
{
return (*this);
}
a += temp;
}
}
KeyBoardIn GetToOverChar(string& a, const char& overchar)
{
char temp;
while ((*this) >> temp)
{
if (temp == overchar)
{
return (*this);
a += temp;
}
}
return false;
}
KeyBoardIn GetForNumber(string& a, const int& number)
{
char temp;
for (int i = 0; i < number; i++)
{
if ((*this) >> temp)
{
a += temp;
}
else
{
return false;
}
}
return (*this);
}
};
KeyBoardIn mkbi;
class KeyBoardOut
{
public:
KeyBoardOut()
{
}
void Down(int n)
{
keybd_event(n, 0, 0, 0);
}
void Up(int n)
{
keybd_event(n, 0, 2, 0);
}
void Fast(int n)
{
Down(n);
Up(n);
}
void CapsLook()
{
Fast(MKB_CapsLook);
}
void Did(int a, int b)
{
Down(a); Down(b);
Up(b); Up(a);
}
void Open(int n)
{
Did(MKB_Win, n);
}
void Close()
{
Did(MKB_Alt, MKB_F4);
}
void Shift(int a)
{
Did(MKB_Shift, a);
}
void CapsToUp()
{
while (!mkbi.CapsIsUp())
{
Fast(MKB_CapsLook);
}
}
void CapsToLower()
{
while (mkbi.CapsIsUp())
{
Fast(MKB_CapsLook);
}
}
KeyBoardOut operator<<(char a)
{
switch (a)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Fast(a);
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
CapsToUp();
Fast(a);
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
CapsToLower();
Fast(a - 32);
break;
case ' ':
Fast(MKB_Space);
break;
case '!':
Shift(MKB_1);
break;
case '@':
Shift(MKB_2);
break;
case '#':
Shift(MKB_3);
break;
case '$':
Shift(MKB_4);
break;
case '%':
Shift(MKB_5);
break;
case '^':
Shift(MKB_6);
break;
case '&':
Shift(MKB_7);
break;
case '*':
Shift(MKB_8);
break;
case '(':
Shift(MKB_9);
break;
case ')':
Shift(MKB_0);
break;
case '-':
Fast(MKB_Minus);
break;
case '=':
Fast(MKB_Equal);
break;
case '[':
Fast(MKB_OpenBracket);
break;
case ']':
Fast(MKB_CloseBracket);
break;
case '\\':
Fast(MKB_BackSlash);
break;
case ';':
Fast(MKB_Semicolon);
break;
case '\'':
Fast(MKB_SingleQuotationMarks);
break;
case ',':
Fast(MKB_Comma);
break;
case '.':
Fast(MKB_Dot);
break;
case '/':
Fast(MKB_Slash);
break;
case '_':
Shift(MKB_Minus);
break;
case '+':
Shift(MKB_Equal);
break;
case '{':
Shift(MKB_OpenBracket);
break;
case '}':
Shift(MKB_CloseBracket);
break;
case '|':
Shift(MKB_BackSlash);
break;
case ':':
Shift(MKB_Semicolon);
break;
case '\"':
Shift(MKB_SingleQuotationMarks);
break;
case '<':
Shift(MKB_Comma);
break;
case '>':
Shift(MKB_Dot);
break;
case '?':
Shift(MKB_Slash);
break;
case '\n':
Fast(MKB_Enter);
break;
}
return *this;
}
KeyBoardOut operator<<(string a)
{
for (int i = 0; i < a.length(); i++)
{
(*this) << a[i];
}
return *this;
}
};
KeyBoardOut mkbo;
class KeyBoard : public KeyBoardIn, public KeyBoardOut
{
public:
KeyBoard()
{
}
};
KeyBoard mkb;
}
}
#endif
(不对,#define似乎能改成enum ……)
2.(鼠标)
(MMouse.hxx)
#ifndef _GLIBCXX_MMOUSE
#define _GLIBCXX_MMOUSE 1
#pragma GCC system_header
#include<windows.h>
#include<winuser.h>
#include<iostream>
#include<string>
namespace std
{
namespace MMouse
{
void sleep(unsigned long long Time)
{
Sleep(Time);
}
enum LorR
{
Left,
Right
};
class Mmouse
{
public:
Mmouse()
{
}
POINT GetXY()
{
POINT P;
GetCursorPos(&P);
return P;
}
Mmouse GetXY(int* x, int* y)
{
*x = GetXY().x;
*y = GetXY().y;
return *this;
}
Mmouse GetXY(int& x, int& y)
{
x = GetXY().x;
y = GetXY().y;
return *this;
}
Mmouse GetXY(POINT* P)
{
GetCursorPos(P);
return *this;
}
Mmouse GetXY(POINT& P)
{
GetCursorPos(&P);
return *this;
}
Mmouse SetXY(const int x, const int y) const
{
SetCursorPos(x, y);
return *this;
}
Mmouse SetXY(const POINT P) const
{
return SetXY(P.x, P.y);
}
Mmouse Down(const int x, const int y, const LorR LR = Left) const
{
if (LR == Left)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
}
else
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0);
}
return *this;
}
Mmouse Down(const POINT P, const LorR LR = Left) const
{
Down(P.x, P.y, LR);
return *this;
}
Mmouse Down(const LorR LR = Left)
{
POINT tP = GetXY();
Down(tP.x, tP.y, LR);
return *this;
}
Mmouse Up(const LorR LR = Left)
{
POINT tP = GetXY();
if (LR == Left)
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
else
{
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
return *this;
}
Mmouse Fast(const int x, const int y, const LorR LR = Left)
{
Down(x, y, LR);
Up(LR);
return *this;
}
Mmouse Fast(const POINT P, const LorR LR = Left)
{
Down(P, LR);
Up(LR);
return *this;
}
Mmouse Fast(const LorR LR = Left)
{
Down(LR);
Up(LR);
return *this;
}
friend istream& operator>>(istream&, LorR&);
};
istream& operator>>(istream& in, LorR& LR)
{
string temp_in;
in >> temp_in;
if (temp_in == "Left")
{
LR = Left;
}
if (temp_in == "Right")
{
LR = Right;
}
return in;
}
Mmouse mouse;
}
}
#endif
(好似有亿点点bug……)
大家自己琢磨一下,可以吗?(来自于6年级小学生的请求……)(http://t.csdn.cn/1SkDK)