增加鼠标键盘监听事件
准备内容
- .c
framework.h pch.h targetver.h
- .hpp
CHookCallback.hpp
- .cpp
CHookCallback.cpp pch.cpp
将以上文件添加到工程包中
配置工程
在主项目.hpp文件中配置
#include "CHookCallback.hpp"
class DllExport xxx :public CHookCallback//继承类
{
public:
virtual void HookCallback(int idHook, int code, WPARAM wParam, LPARAM lParam) override; //重构方法
}
在主项目.cpp文件中配置
构造函数
AGSekectTest::AGSekectTest()
{
try
{
AddHook(WH_KEYBOARD); //箭头键盘
//AddHook(WH_MOUSE);//箭头鼠标
}
catch(exception& ex)
{
throw;
}
}
重构方法
HookCallback(int idHook, int nCode, WPARAM wParam, LPARAM lParam)
void AGSekectTest::HookCallback(int idHook, int nCode, WPARAM wParam, LPARAM lParam)
{
char msg[256];
if (idHook == WH_KEYBOARD)//键盘事件
{
if (nCode == HC_ACTION)
{
UF_UI_open_listing_window();
int vkCode = (int)wParam;
if (GetAsyncKeyState(vkCode)&0x8000)//按下事件
{
UF_UI_write_listing_window(to_string(vkCode).c_str());
}
}
}
else if (idHook == WH_MOUSE)//鼠标事件
{
if (nCode == HC_ACTION)
{
if (wParam == WM_MOUSEMOVE) //鼠标滚动
{
//UpdateStringBlock(*this, 1);
}
else if (wParam == WM_LBUTTONDOWN) //左键按下
{
//UpdateStringBlock(*this, 2);
}
}
}
}
评论区