|

楼主 |
发表于 2014-6-23 15:09:41
|
显示全部楼层
// ActiveKey.cpp : 定义 DLL 的初始化例程。
//
#include "stdafx.h"
#include <afxwin.h>
#include <afxdllx.h>
#include "ActiveKey.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static AFX_EXTENSION_MODULE ActiveKeyDLL = { NULL, NULL };
#pragma data_seg("shareddata")
HHOOK glhHook=NULL;
HINSTANCE glhInstance=NULL;
#pragma data_seg()
extern "C"LRESULT WINAPI KeyboardProc(int nCode,WPARAM wParam,LPARAM LParam)
{
if(nCode >=0)
{
if(wParam ==0X78 )
{
CPoint newPoint,oldPoint;
GetCursorPos(&oldPoint);
newPoint.x=oldPoint.x+40;
newPoint.y=oldPoint.y+10;
SetCursorPos(newPoint.x,newPoint.y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),0,0);
keybd_event(0x52,MapVirtualKey(0x52,0),0,0);
keybd_event(0x52,MapVirtualKey(0x52,0),KEYEVENTF_KEYUP,0);
keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),KEYEVENTF_KEYUP,0);
SetCursorPos(oldPoint.x,oldPoint.y);
}
}
return CallNextHookEx(glhHook,nCode,wParam,LParam);
}
CKeyHook::CKeyHook(){}
CKeyHook::~CKeyHook()
{
if(glhHook)
Stop();
}
HHOOK CKeyHook::Start()
{
glhHook = SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,glhInstance,0);
return glhHook;
}
BOOL CKeyHook::Stop()
{
BOOL bResult = true;
if(glhHook)
bResult = UnhookWindowsHookEx(glhHook);
return bResult;
}
extern "C" int APIENTRY
DLLMain(HINSTANCE hInstance,DWORD dwReason,LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(lpReserved);
if(dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("ActiveKey.DLL Initializing!\n");
if(!AfxInitExtensionModule(ActiveKeyDLL,hInstance))
return 0 ;
new CDynLinkLibrary(ActiveKeyDLL);
glhInstance =hInstance;
}
else if(dwReason ==DLL_PROCESS_DETACH)
{
TRACE0("ActiveKey.DLL Terminating!\n");
AfxTermExtensionModule(ActiveKeyDLL);
}
return 1;
} |
|