首页 > 其他分享 >键盘钩子(切勿用作非法用途)

键盘钩子(切勿用作非法用途)

时间:2023-04-25 10:09:35浏览次数:25  
标签:wParam return nCode 切勿 钩子 键盘 hook include procedure


// keyboardhook.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<windows.h>
using namespace std;

HHOOK g_Hook;
LRESULT CALLBACK LowLevelKeyboardProc(INT nCode, WPARAM wParam, LPARAM lParam)
{
	KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
	BOOL bControlKeyDown = 0;
	
    switch (nCode)
	{
	case HC_ACTION:
		{
			// Check to see if the CTRL key is pressed
			bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
			//Check   to see if the  Cap  is   pressed
			BOOL bCap = GetAsyncKeyState(VK_CAPITAL) >> ((sizeof(SHORT) * 8) - 1);
			//Disable CTRL+ESC
			if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
				return 1;
			if(wParam == WM_KEYUP)
				printf("%c", pkbhs->vkCode);

			break;
		}
	}
	//Passes the hook information to the next hook procedure in the current hook chain. A hook procedure can call this function either before or after processing the hook information.
	return CallNextHookEx(g_Hook, nCode, wParam, lParam); //回调
	//return 1;
}


int _tmain(int argc, _TCHAR* argv[])
{
	MSG msg;
	//Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.
	g_Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,
		(HOOKPROC)LowLevelKeyboardProc, GetModuleHandleW(0),0); 
	while(GetMessageW(&msg,0,0,0))DispatchMessageW(&msg);
	return 0;
}


标签:wParam,return,nCode,切勿,钩子,键盘,hook,include,procedure
From: https://blog.51cto.com/u_16087831/6223413

相关文章

  • Angular系列 -> 生命周期钩子
    简介:Angular指令的生命周期,是用来记录指令从创建、应用及销毁的过程。Angular提供了一系列与指令生命周期相关的钩子,便于我们监控指令生命周期的变化,并执行相关的操作。生命周期介绍: ngOnChanges:当数据绑定输入属性的值发生变化时;@input属性(输入属性)发生变化时;ngO......
  • Apple设备_Mac键盘快捷键
    0、官方链接Mac键盘快捷键Mac辅助功能快捷键Safari浏览器键盘及其他快捷键1、剪切、拷贝、粘贴和其他常用快捷键Command-X:剪切所选项并拷贝到剪贴板。Command-C:将所选项拷贝到剪贴板。这同样适用于“访达”中的文件。Command-V:将剪贴板的内容粘贴到当前文稿或......
  • 51单片机学习笔记 STC89C52RC (05)矩阵键盘和独立键盘(轻触开关)
    按键抖动,需要消抖 原理图来自清翔电子一、独立键盘模块1.可以直接获取 P3^0对应S2 P3^1对应S3 P3^2对应S4 P3^3对应S5 的电压当轻触开关按下时,电流会流向GND,此时这一路的电压为0V,松开轻触开关,又变为5V //第一种方法:单个I/O口检测控制#include<reg51.h>sbi......
  • react 生命周期钩子函数
    1、挂载:construct、getDerivedStateFromProps、render、componentDidMounted2、更新:getDerivedStateFromProps、componentWillUpdate、render、getSnapshotBeforeUpdate、componentDidUpdated3、卸载:componentWillUnmounted4、请求放在componentDidMount里react生命周期图:h......
  • uiautomator2+python-模拟安卓键盘输入
    这种方法通常用于不知道控件的情况下的输入。第一步需要切换输入法,然后发送adb广播命令,具体使用方法如下d.set_fastinput_ime(True)先清除掉文本框的内容d.press("back")为收起键盘,可能存在键盘阻挡住别的页面元素,需要收起键盘d=u2.connect()d.set_fastinput_ime(Tr......
  • 类中自定义函数并调用and使用钩子函数打印类中变量
    在一个类中自定义一个函数A,并在前向传播函数forword中调用这个函数假设您正在编写一个PyTorch模型,您可以按照以下方式在类中定义函数A,并在forward函数中调用它:importtorchimporttorch.nnasnnclassMyModel(nn.Module):def__init__(self):super(MyMod......
  • android中软键盘的打开关闭及判断操作
    /**隐藏软键盘**/Viewview=getWindow().peekDecorView();if(view!=null){InputMethodManagerinputmanger=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);inputmanger.hideSoftInputFromWindow(view......
  • python+playwright 学习-53 模拟键盘操作-复制粘贴相关
    前言playwright可以模拟键盘操作,定位到元素使用press()方法press()方法介绍locator.press()方法聚焦所选元素并产生单个击键。它接受在键盘事件的keyboardEvent.key属性中发出的逻辑键名称:Backquote,Minus,Equal,Backslash,Backspace,Tab,Delete,Escape,ArrowDown,......
  • 汉源高科VGA光端机+1路立体声音频+USB鼠标键盘控制光纤延长器
    汉源高科VGA光端机+1路立体声音频+USB鼠标键盘控制光纤延长器......
  • 汉源高科高清DVI音视频光端机+USB键盘鼠标KVM控制dvi光纤收发器延长器
    汉源高科高清DVI音视频光端机+USB键盘鼠标KVM控制dvi光纤收发器延长器......