大家好,又见面了,我是你们的朋友全栈君。
HHOOK keyHook = NULL;
//先声明函数,实现在下面
LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam);
//初始化钩子,关闭键盘事件(除了ALT+CTRL+DELETE)
void initHook()
{
keyHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyProc, GetModuleHandle(NULL), 0);
}
//销毁钩子
void unHook()
{
if (keyHook)
{
UnhookWindowsHookEx(keyHook);
}
}
//钩子用的函数
LRESULT CALLBACK keyProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//在WH_KEYBOARD_LL模式下lParam 是指向KBDLLHOOKSTRUCT类型地址
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
//如果nCode等于HC_ACTION则处理该消息,如果小于0,则钩子子程就必须将该消息传递给 CallNextHookEx
if (nCode == HC_ACTION)
{
if (pkbhs->vkCode == VK_ESCAPE)
{
CLogHelp::ITCLog("keyProc---->Esc");
if (g_pthisDlg)
{
CLogHelp::ITCLog("Closescreen_FULL");
g_pthisDlg->Closescreen_FULL();
}
}
else if (pkbhs->vkCode == VK_ESCAPE && GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_SHIFT) & 0x8000) {
//qDebug() << "Ctrl+Shift+Esc";
}
else if (pkbhs->vkCode == VK_ESCAPE && GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
//qDebug() << "Ctrl+Esc";
}
else if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
{
CLogHelp::ITCLog("Alt+Tab ");
}
else if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags &LLKHF_ALTDOWN)
{
CLogHelp::ITCLog("Alt+Esc");
}
else if (pkbhs->vkCode == VK_LWIN || pkbhs->vkCode == VK_RWIN)
{
CLogHelp::ITCLog("VK_LWIN vs VK_RWIN ");
}
else if (pkbhs->vkCode == VK_F4 && pkbhs->flags & LLKHF_ALTDOWN)
{
CLogHelp::ITCLog("Alt+F4 ");
}
else if (pkbhs->vkCode == VK_F1 && pkbhs->flags &LLKHF_ALTDOWN)
{
CLogHelp::ITCLog("Alt+F1 back room ");
unHook();
}
else if (pkbhs->vkCode == VK_F1)
{
CLogHelp::ITCLog("F1 Key press ");
}
return 1;//返回1表示截取消息不再传递,返回0表示不作处理,消息继续传递
}
return CallNextHookEx(keyHook, nCode, wParam, lParam);
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/130227.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...