识别键盘按下
# include <stdio.h>
# include <windows.h>
int main()
{
int E,S,C;
while(1)
{
//GetKeyState只能识别大写字母对应的ASCII码值
E = GetKeyState(toascii('E'));//获取E键状态
S = GetKeyState(toascii('S'));//获取S键状态
C = GetKeyState(toascii('C'));//获取C键状态
//E键、S键和C键同时被按下
if(E<0 && S<0 && C<0)
{
printf("ESC\n");
}
}
return 0;
}
模拟键盘按下
# include <stdio.h>
# include <windows.h>
int main()
{
keybd_event('E', 0, 0, 0); //按下
keybd_event('S', 0, 0, 0); //按下
keybd_event('C', 0, 0, 0); //按下
keybd_event('E', 0, 2, 0); //松开
keybd_event('S', 0, 2, 0); //松开
keybd_event('C', 0, 2, 0); //松开
return 0;
}
先运行识别键盘按下程序,再运行模拟键盘按下程序,前者将打印出ESC