Re: [問題] 我想抓取鍵盤上上下左右鍵的十進制值
答案出來了
程式如下
0xe0 + 0x48: 向上按鍵
0xe0 + 0x50: . . .
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
int main()
{
int ch1;
for (;;) {
// remove type- ahead
while (kbhit()) {
getch();
}
printf("\n\n Press [Esc] for stop! ...");
do {
// wait for keyPressed
} while (!kbhit());
ch1= getch();
printf("\n");
printf("ch1= 0x%02x\n", ch1);
if (ch1 == 0x1b) {
exit(1);
}
// remove extra keyStroke
while (kbhit()) {
ch1= getch();
printf("*** ch1= 0x%02x\n", ch1);
}
}
return(0);
}// end of main()
※ 引述《sjgau (sjgau)》之銘言:
: 鍵盤上的某些 key, 會送出兩個 code
: 0 + 0xXX
: 譬如說 : F1 - F12
: 所以,當你偵測到
: ch == 0x00 的時候,
: 你要趕快抓 下一個 code
: 就是你要的的 0 + 0xXX
: ※ 引述《icetofux (豆腐)》之銘言:
: : 我想抓取鍵盤上上下左右鍵的十進制值,為此寫了下面這段:
: : char ch;
: : for(;;)
: : {
: : cout<<"KEYIN A CHAR:";
: : ch=getch();
: : cout<<endl;
: : cout<<"char:"<<ch<<",ASCII:"<<int(ch)<<endl;
: : }
: : 從網路上的ASCII table來看,從A~Z、a~z甚至是@#%等符號都可以正確顯示出
: : 對應的ASCII碼十進制值,但上下左右卻不行,請問是為什麼呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.231.35.110
推
06/11 18:06, , 1F
06/11 18:06, 1F
→
06/12 04:49, , 2F
06/12 04:49, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):