在VIEW的OnKeyDown中:
void CTestkbView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
   switch (nChar)//分析按键
   {
     case VK_UP :      //向上的方向键
     case VK_SHIFT  :  //shift键
     case VK_RETURN:   //回车键,但是按下回车不起作用,上面两个都正常
   }
}为什么VK_RETURN对应的不是回车键?因为用调试的方式,按回车也不能进
到对应的代码,而其它的都正常.
该怎么写?

解决方案 »

  1.   

    switch (nChar)
     {
     case VK_LEFT:
     ...
      break;
     case VK_RIGHT:
     ...
      break;
     case VK_UP:
     ...
      break;
     case VK_DOWN:
    ...
      break;
    case VK_RETURN:
    ...
      break;
    }from 
    http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_cwnd.3a3a.onkeydown.asp?frame=true
    nChar 
    Specifies the virtual key code of the given key. For a list of of standard virtual key codes, see Winuser.h nRepCnt 
    Repeat count (the number of times the keystroke is repeated as a result of the user holding down the key). nFlags 
    Specifies the scan code, key-transition code, previous key state, and context code
      

  2.   

    void CT66View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    switch(nChar)
    {
    case VK_UP:
    AfxMessageBox("1");
    break;
    case VK_SHIFT:
    AfxMessageBox("2");
    break;
    case VK_RETURN:
    AfxMessageBox("3");
    break;
    } CView::OnKeyDown(nChar, nRepCnt, nFlags);
    }
    我这操作可以,不知道你为什么不行了...
      

  3.   

    对了,我也想问问,在对话框里面怎么响应键盘事件??
    还有,VK_1,VK_2,....为什么不对,键1,键2.....应该怎么表示???
      

  4.   

    你程序中没有break,并少了CView::OnKeyDown(nChar, nRepCnt, nFlags);键1,2,3...分别用 0x30,31,32..表示
    见msdn