天天看點

c語言的按鍵,c語言獲得鍵盤的按鍵

該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓

TC 2.0版

#include

#include

int main()

{

int key;

while(1)

{

key=getch();

if(key==27) break;

if(key>31 && key<127)

{printf("You have pressed %c Press ESC to exit!\n",key);continue;}

key=getch();

if(key==72) printf(" UP Press ESC to exit!\n");

if(key==80) printf(" DOWN Press ESC to exit!\n");

if(key==75) printf(" LEFT Press ESC to exit!\n");

if(key==77) printf(" RIGHT Press ESC to exit!\n");

}

return 0;

}

VC 6.0版

#include

#include

int main()

{

int key;

while(1)

{

key=getch();

if(key==27) break;

if(key>31 && key<127)

{printf("按了 %c 鍵 按 ESC退出!\n",key);continue;}

key=getch();

if(key==72) printf("按了 上 鍵 按 ESC退出!\n");

if(key==80) printf("按了 下 鍵 按 ESC退出!\n");

if(key==75) printf("按了 左 鍵 按 ESC退出!\n");

if(key==77) printf("按了 右 鍵 按 ESC退出!\n");

}return 0;

}