• 大小: 71KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C/C++
  • 标签: C++  钩子  按键精灵  

资源简介

C++钩子模仿按键精灵屏幕录制

资源截图

代码片段和文件信息

// #include 
// #include 
// #include “../Common/Definition.h“
// using namespace std;
#include “KMHookDll.h“

CKMHookDll* CKMHookDll::m_pInstance = NULL;

BOOL WINAPI DllMain(HINSTANCE hinstDLLDWORD fdwReasonLPVOID lpvReserved )
{
CKMHookDll::GetInstance()->SetGlobalInstance(hinstDLL);
return TRUE;
}

LRESULT CALLBACK RecHook(int codeWPARAM wParamLPARAM lParam)
{

static int recOK = 1;
if(code<0)
{
return CallNextHookEx(CKMHookDll::GetInstance()->GetRecHook()codewParamlParam);
}
else if(code==HC_SYSMODALON)
{
recOK = 0;
}
else if(code==HC_SYSMODALOFF)
{
recOK = 1;
}
else if(recOK && (code==HC_ACTION))
{
EVENTMSG action = *(EVENTMSG*)lParam;
//此处根据条件过滤
//  if (action.message == WM_LBUTTONDOWN || action.message == WM_LBUTTONUP)
//  {
//  return 0;
//  }
CKMHookDll::GetInstance()->AddEvent(action);
//m_vecAction.push_back(action);
//recordedEvent++;
}
return 0;
}


LRESULT CALLBACK PlayHook(int codeWPARAM wParamLPARAM lParam)
{
static BOOL fDelay;
static int playOK = 1;
if(code<0)
{
return CallNextHookEx(CKMHookDll::GetInstance()->GetPlayHook()codewParamlParam);
}
else if(code==HC_SYSMODALON)
{
playOK = 0;
}
else if(code==HC_SYSMODALOFF)
{
playOK = 1;
}
else if(playOK && (code==HC_GETNEXT))
{
if(fDelay)
{
fDelay = FALSE;
return 50;
}
*((EVENTMSG*)lParam) = CKMHookDll::GetInstance()->GetVecAt(CKMHookDll::GetInstance()->GetPlayedEvent());
}
else if(playOK && (code==HC_SKIP))
{
fDelay = TRUE;
CKMHookDll::GetInstance()->IncPlayedEvent();
}
if(CKMHookDll::GetInstance()->GetPlayedEvent()>=CKMHookDll::GetInstance()->GetVecSize())
{
UnhookWindowsHookEx(CKMHookDll::GetInstance()->GetPlayHook());
}
return 0;
}

CKMHookDll::CKMHookDll()
: m_bIsKeyDown(false)
 m_bIsMouseDown(false)
 m_bIsMouseMove(false)
 m_pVecAction(NULL)
 m_hRecHook(NULL)
 m_hPlayHook(NULL)
 m_nPlayedEvent(0)
{
m_pVecAction = new vector;
}


CKMHookDll::~ CKMHookDll()
{

}

CKMHookDll* CKMHookDll::GetInstance()
{
if (m_pInstance == NULL)
{
m_pInstance = new CKMHookDll;
}
return m_pInstance;
}

void CKMHookDll::InstallHook(bool bIsKeyDownbool bIsMouseDownbool bIsMouseMove/*HWND hwnd*/)
{
if (!m_pVecAction->empty())
{
m_pVecAction->clear();
}
m_bIsKeyDown = bIsKeyDown;
m_bIsMouseDown = bIsMouseDown;
m_bIsMouseMove = bIsMouseMove;
m_hRecHook = SetWindowsHookEx(WH_JOURNALRECORD(HOOKPROC)RecHookm_hInst0);
}

void CKMHookDll::UnInstallHook()
{
UnhookWindowsHookEx(m_hRecHook);
}

void CKMHookDll::Runscript()
{
m_nPlayedEvent = 0;
m_hPlayHook = SetWindowsHookEx(WH_JOURNALPLAYBACK(HOOKPROC)PlayHookm_hInst0);
}

void CKMHookDll::SetGlobalInstance(HINSTANCE instance)
{
m_hInst = instance;
}

HHOOK CKMHookDll::GetRecHook()
{
return m_hRecHook;
}

HHOOK CKMHookDll::GetPlayHook()
{
return m_hPlayH

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3414  2016-03-24 14:11  MFCApplication1\KMHookDll\KMHookDll.cpp

     文件         19  2016-03-23 11:07  MFCApplication1\KMHookDll\KMHookDll.def

     文件        986  2016-03-24 14:24  MFCApplication1\KMHookDll\KMHookDll.h

     文件       7385  2016-03-24 13:55  MFCApplication1\KMHookDll\KMHookDll.vcxproj

     文件       2485  2016-03-24 14:08  MFCApplication1\MFCApplication1\MFCApplication1.cpp

     文件        496  2016-03-24 14:08  MFCApplication1\MFCApplication1\MFCApplication1.h

     文件      10766  2016-03-24 14:24  MFCApplication1\MFCApplication1\MFCApplication1.rc

     文件       6210  2016-03-24 14:24  MFCApplication1\MFCApplication1\MFCApplication1.vcxproj

     文件       3760  2016-03-24 14:25  MFCApplication1\MFCApplication1\MFCApplication1Dlg.cpp

     文件        684  2016-03-24 14:25  MFCApplication1\MFCApplication1\MFCApplication1Dlg.h

     文件       4013  2016-03-24 14:08  MFCApplication1\MFCApplication1\ReadMe.txt

    .......     67777  2012-01-11 01:22  MFCApplication1\MFCApplication1\res\MFCApplication1.ico

     文件        686  2016-03-24 14:08  MFCApplication1\MFCApplication1\res\MFCApplication1.rc2

     文件       1248  2016-03-24 14:25  MFCApplication1\MFCApplication1\resource.h

     文件        148  2016-03-24 14:08  MFCApplication1\MFCApplication1\stdafx.cpp

     文件       1578  2016-03-24 14:08  MFCApplication1\MFCApplication1\stdafx.h

     文件        234  2016-03-24 14:08  MFCApplication1\MFCApplication1\targetver.h

    ..A..H.        58  2016-03-24 14:08  MFCApplication1\MFCApplication1.opensdf

     文件       1378  2016-03-24 14:24  MFCApplication1\MFCApplication1.sln

    ..A..H.     23040  2016-03-24 14:24  MFCApplication1\MFCApplication1.v11.suo

     目录          0  2016-03-24 14:08  MFCApplication1\MFCApplication1\res

     目录          0  2016-03-24 14:30  MFCApplication1\KMHookDll

     目录          0  2016-03-24 14:30  MFCApplication1\MFCApplication1

     目录          0  2016-03-24 14:29  MFCApplication1

----------- ---------  ---------- -----  ----

               136365                    24


评论

共有 条评论