//****************** 類mk頭文件mk.h **************************
#if !defined(AFX_MK_H__B024D48F_090A_4F6F_A199_32996DF699B3__INCLUDED_)
#define AFX_MK_H__B024D48F_090A_4F6F_A199_32996DF699B3__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "winable.h"
class mk
{
public:
mk();
static void Key(BYTE k, int mSeconds=0);//按一個鍵,mSeconds表按鍵後到
//下一次操作延遲的時間:ms
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 // !defined(AFX_MK_H__B024D48F_090A_4F6F_A199_32996DF699B3__INCLUDED_)
//****************** 類mk頭文件mk.h end**************************
//****************** 類mk實現文件mk.cpp **************************
#include "stdafx.h"
#include "mk.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
mk::mk()
{
}
mk::~mk()
{
}
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)
{
//法1
//keybd_event(k1, 0, 0 ,0);
//keybd_event(k2, 0, 0 ,0);
//keybd_event(k2, 0, KEYEVENTF_KEYUP,0);
//keybd_event(k1, 0, KEYEVENTF_KEYUP,0);
//法2,更通用,但須先#include "winable.h"
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_LE
[1] [2] [3] 下一頁