编程,显示用户在键盘上所按键的扫描码,ASCII码和字符(若按下的是非字符键,只显示扫描码),同时显示Caps Lock,Shift和Alt的情况。按下Esc键(扫描码为1)结束程序。
1 #include <bios.h> 2 #include <stdio.h> 3 int main() 4 { 5 int key; 6 union 7 { 8 int key; 9 char c[2]; 10 } u; 11 char flag; 12 u.key=bioskey(0); 13 while(u.c[1]!=1) 14 { 15 printf("code:0x%x ",u.c[1]); 16 if(u.c[0]!=0) 17 printf("ASCII:%d char:%c", u.c[0], u.c[0]); 18 printf(" "); 19 key=bioskey(2); 20 if(key&64) 21 printf("Caps LOCK On "); 22 else 23 printf("Caps LOCK Off "); 24 if(key&1||key&2) 25 printf("Shift "); 26 else 27 printf("No Shift "); 28 if(key&8) 29 printf("Alt "); 30 else 31 printf("No Alt "); 32 33 u.key=bioskey(0); 34 } 35 return 0; 36 }