#include <winable.h>
class mk
{
public:
mk(){}
////按一个键,mSeconds表按键后到下一次操作延迟的时间:ms
static void Key( BYTE k, int mSeconds=0);
static void Key2( BYTE k1,BYTE k2, int mSeconds=0);//按2个键
static void Key3( BYTE k1,BYTE k2,BYTE k3,int mSeconds=0);//按3个键
static void Click( int x, int y, int mSeconds=0);//单击
static void RClick( int x, int y, int mSeconds=0);//右击
static void DClick( int x, int y, int mSeconds=0);//双击
static void CtrlClick( int x, int y, int mSeconds=0);//Ctrl+单击
static void Drag(int x1,int y1, int x2, int y2, int mSeconds=0);//鼠标拖动
virtual ~mk(){}
};
#endif
/*
VK_LBUTTON 01 鼠标左键
VK_RBUTTON 02 鼠标右键
VK_CANCEL 03 Control-break 过程
VK_MBUTTON 04 鼠标中键
VK_BACK 08 BACKSPACE 键
VK_TAB 09 TAB 键
VK_CLEAR 0C CLEAR 键
VK_RETURN 0D ENTER 键
VK_SHIFT 10 SHIFT 键
VK_CONTROL 11 CTRL 键
VK_MENU 12 ALT 键
VK_PAUSE 13 PAUSE 键
VK_CAPITAL 14 CAPS LOCK 键
VK_ESCAPE 1B ESC 键
VK_SPACE 20 SPACEBAR
VK_PRIOR 21 PAGE UP 键
VK_NEXT 22 PAGE DOWN 键
VK_END 23 END 键
VK_HOME 24 HOME 键
VK_LEFT 25 LEFT ARROW 键
VK_UP 26 UP ARROW 键
VK_RIGHT 27 RIGHT ARROW 键
VK_DOWN 28 DOWN ARROW 键
VK_SELECT 29 SELECT 键
VK_EXECUTE 2B EXECUTE 键
VK_SNAPSHOT 2C PRINT SCREEN键(用于Windows 3.0及以后版本)
VK_INSERT 2D INS 键
VK_DELETE 2E DEL 键
VK_HELP 2F HELP 键
VK_LWIN 5B Left Windows 键 (Microsoft自然键盘)
VK_RWIN 5C Right Windows 键 (Microsoft自然键盘)
VK_APPS 5D Applications 键 (Microsoft自然键盘)
VK_NUMPAD0 60 数字小键盘上的 0 键
VK_NUMPAD1 61 数字小键盘上的 1 键
VK_NUMPAD2 62 数字小键盘上的 2 键
VK_NUMPAD3 63 数字小键盘上的 3 键
VK_NUMPAD4 64 数字小键盘上的 4 键
VK_NUMPAD5 65 数字小键盘上的 5 键
VK_NUMPAD6 66 数字小键盘上的 6 键
VK_NUMPAD7 67 数字小键盘上的 7 键
VK_NUMPAD8 68 数字小键盘上的 8 键
VK_NUMPAD9 69 数字小键盘上的 9 键
VK_MULTIPLY 6A Multiply 键
VK_ADD 6B Add 键
VK_SEPARATOR 6C Separator 键
VK_SUBTRACT 6D Subtract 键
VK_DECIMAL 6E Decimal 键
VK_DIVIDE 6F Divide 键
VK_F1 70 F1 键
VK_F2 71 F2 键
VK_F3 72 F3 键
VK_F4 73 F4 键
VK_F5 74 F5 键
VK_F6 75 F6 键
VK_F7 76 F7 键
VK_F8 77 F8 键
VK_F9 78 F9 键
VK_F10 79 F10 键
VK_F11 7A F11 键
VK_F12 7B F12 键
VK_F13 7C F13 键
VK_F14 7D F14 键
VK_F15 7E F15 键
VK_F16 7F F16 键
VK_F17 80H F17 键
VK_F18 81H F18 键
VK_F19 82H F19 键
VK_F20 83H F20 键
VK_F21 84H F21 键
VK_F22 85H F22 键
VK_F23 86H F23 键
VK_F24 87H F24 键
VK_NUMLOCK 90 NUM LOCK 键
VK_SCROLL 91 SCROLL LOCK 键
VK_ATTN F6 Attn 键
VK_CRSEL F7 CrSel 键
VK_EXSEL F8 ExSel 键
VK_EREOF F9 Erase EOF 键
VK_PLAY FA Play 键
VK_ZOOM FB Zoom 键
VK_OEM_CLEAR FE Clear 键
*/
void mk::Click(int x, int y, int mSeconds)
{
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(mSeconds);
}
void mk::DClick(int x, int y, int mSeconds)
{
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(mSeconds);
}
void mk::Drag(int x1, int y1, int x2, int y2, int mSeconds)
{
SetCursorPos(x1,y1);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
SetCursorPos(x2,y2);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Sleep(mSeconds);
}
void mk::RClick(int x, int y, int mSeconds)
{
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
Sleep(mSeconds);
}
void mk::Key(BYTE k, int mSeconds)
{
keybd_event(k,0,0,0);
keybd_event(k,0,KEYEVENTF_KEYUP,0);
Sleep(mSeconds);
}
void mk::Key2(BYTE k1, BYTE k2, int mSeconds)
{
INPUT input[4];
memset(input,0,sizeof(input));
input[0].type=input[1].type=input[2].type=input[3].type=INPUT_KEYBOARD;
input[0].ki.wVk=input[3].ki.wVk=k1;
input[1].ki.wVk=input[2].ki.wVk=k2;
input[2].ki.dwFlags = input[3].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(4, input, sizeof(INPUT));
Sleep(mSeconds);
}
void mk::CtrlClick(int x, int y, int mSeconds)
{
SetCursorPos(x,y);
keybd_event(VK_CONTROL ,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
Sleep(mSeconds);
}
void mk::Key3(BYTE k1, BYTE k2, BYTE k3, int mSeconds)
{
if(k1==VK_CONTROL&&k2==VK_MENU&&k3==VK_DELETE)
ShellExecute(NULL,NULL,"taskmgr.exe",NULL,NULL,SW_SHOW);
else
{
INPUT input[6];
memset(input,0,sizeof(input));
input[0].type=input[1].type=input[2].type=input[3].type=input[4].type=input[5].type=INPUT_KEYBOARD;
input[0].ki.wVk=input[5].ki.wVk=k1;
input[1].ki.wVk=input[4].ki.wVk=k2;
input[2].ki.wVk=input[3].ki.wVk=k3;
input[3].ki.dwFlags=input[4].ki.dwFlags=input[5].ki.dwFlags=KEYEVENTF_KEYUP;
SendInput(6, input, sizeof(INPUT));
}
Sleep(mSeconds);
}