69,373
社区成员
发帖
与我相关
我的任务
分享
//The _getch function reads a single character from the console without echoing.
//Function can not be used to read CTRL+Break.
//When reading a function key or an arrow key,
//_getch must be called twice; the first call returns 0 or 0xE0,
//and the second call returns the actual key code.
#include <conio.h>
#include <windows.h>
void main() {
unsigned short k;
while (1) {
Sleep(100);
k=getch();
if (27==k) break;//按Esc键退出
if (0==k||0xe0==k) k|=getch()<<8;//非字符键
cprintf("%04x pressed.\r\n",k);
}
}
//The _getch function reads a single character from the console without echoing.
//Function can not be used to read CTRL+Break.
//When reading a function key or an arrow key,
//_getch must be called twice; the first call returns 0 or 0xE0,
//and the second call returns the actual key code.
#include <conio.h>
#include <windows.h>
void main() {
unsigned short k;
while (1) {
Sleep(100);
k=getch();
if (27==k) break;//按Esc键退出
if (0==k||0xe0==k) k|=getch()<<8;//非字符键
cprintf("%04x pressed.\r\n",k);
}
}
#include <conio.h>
#include <windows.h>
void main() {
unsigned short k;
while (1) {
Sleep(100);
k=getch();
if (27==k) break;//按Esc键退出
if (0==k||0xe0==k) k|=getch()<<8;//非字符键
cprintf("%04x pressed.\r\n",k);
}
}
#include <conio.h>
#include <stdio.h>
int main()
{
int c;
while(1)
{
c=getch();
switch(c)
{
case 72:
printf("up\n");
break;
case 75:
printf("left\n");
break;
case 77:
printf("right\n");
break;
case 80:
printf("down\n");
break;
case 27: // ESC
return 1;
}
}
return 0;
}
#include <conio.h>
#include <windows.h>
void main() {
unsigned short k;
while (1) {
Sleep(100);
k=getch();
if (27==k) break;//按Esc键退出
if (0==k) k=getch()<<8;//非字符键
cprintf("%04x pressed.\r\n",k);
}
}