键盘响应
- 插入函数:在...对话框/menu中进入建立类模式,建立preTranslateMessage(MSG * pMsg)
在CXXXView类中,添加:
1 BOOL CMy9_1View::PreTranslateMessage(MSG* pMsg) 2 { 3 // TODO: Add your specialized code here and/or call the base class 4 if(pMsg->message == WM_KEYDOWN) //捕捉到键盘 5 { 6 switch(pMsg->wParam) 7 { 8 case VK_UP: //方向键↑
9 PHI += add_p; 10 //PHI = 360%Round(PHI); 11 Onbegin(RR, DD, PHI, THETA);//添加自己的代码,下同 12 break; 13 14 case VK_DOWN: //方向键↓ 15 PHI -= add_p; 16 //PHI = 360%Round(PHI); 17 Onbegin(RR, DD, PHI, THETA); 18 break; 19 20 case VK_RIGHT: //方向键→ 21 THETA -= add_t; 22 Onbegin(RR, DD, PHI, THETA); 23 break; 24 25 case VK_LEFT: //方向键← 26 THETA += add_t; 27 Onbegin(RR, DD, PHI, THETA); 28 break; 29 30 case 'B'://响应'B'键 31 RR -= add_r; 32 Onbegin(RR, DD, PHI, THETA); 33 break; 34 35 case 'S'://响应'S'键 36 RR += add_r; 37 Onbegin(RR, DD, PHI, THETA); 38 break; 39 40 case ' '://响应Space键 41 if(flag_space == true) 42 { 43 KillTimer(1); 44 flag_space = false; 45 } 46 47 else if(flag_space == false) 48 { 49 SetTimer(1, 100, NULL); 50 flag_space = true; 51 } 52 53 break; 54 55 default: 56 break; 57 } 58 } 59 return CView::PreTranslateMessage(pMsg); 60 }
如果想要响应具体的字母 case ’字母’ 即可!