Re: [問題] 我想抓取鍵盤上上下左右鍵的十進制值

看板Programming作者 (sjgau)時間17年前 (2008/06/11 14:30), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串3/3 (看更多)
答案出來了 程式如下 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
0xe0正是-32
06/11 18:06, 1F

06/12 04:49, , 2F
為什麼不 (unsigned char) --> 224
06/12 04:49, 2F
文章代碼(AID): #18Jt4GcJ (Programming)
討論串 (同標題文章)
文章代碼(AID): #18Jt4GcJ (Programming)