|
>>私のところでも0xE0になるのですがこれは環境の違い?
> ん〜どうなんでしょうねぇ〜
http://www.microsoft.com/JAPAN/developer/library/vccore/_crt__getch.2c_._getche.htm
にもあるように、処理系依存のようですね。
>実は、↑で示したプログラムも間違いなんですよねぇ(><;)
>大文字の'H','K','M','P'を押してみてください。
>プログラムが終了すると思います。
これは、0x00か0xE0のときに再入力でいいのでは?
#include <stdio.h>
#include <conio.h>
main()
{
int c, inkey=-1;
while(1){
c=getch();
/* 矢印あるいはファンクションキーは再読込み */
if(c == 0x00 || c == 0xE0){
c=getch();
if(c==0x48){ /* 上 */
inkey=0;
}else if(c==0x4b){ /* 左 */
inkey=1;
}else if(c==0x50){ /* 下 */
inkey=2;
}else if(c==0x4d){ /* 右 */
inkey=3;
}
if(inkey!=-1)
break;/*上下左右が押されてたら終了 */
}
else {
printf("%d :",c);
putchar(c);
putchar('\n');
}
}
printf("END=%d\n(0:↑,1:←,2:↓,3:→)",inkey);
return (inkey);
}
|