比如说我按下了SHIFT键,怎么才能知道我按下了SHIFT键,就象CAPSLOCK那样按下了键盘的灯会亮

解决方案 »

  1.   

    就使用:
    if(::GetKeyState(VK_SHIFT)<0)
       AfxMessageBox("Shift Key is down!");
      

  2.   

    if(::GetAsyncState(VK_SHIFT)>>8-1)
    ....
      

  3.   

    void CTesttoolDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    if(::GetKeyState(VK_SHIFT)<0)
               AfxMessageBox("Shift Key is down!");
    CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
    }
    我这样用了,可是好象每用啊,对话框弹不出来
      

  4.   

    void CTesttoolDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
       AfxMessageBox("Shift Key is down!"); CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
    }
    连这样都没用,程序都没响应,该怎么办呢?
      

  5.   

    对话框是不能直接处理OnKeyDown的,在PreTranslateMessage函数里处理
    CDialog::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message==WM_KEYDOWN)
        {
            switch(pMsg->wParam)
            {
               case VK_LEFT:
                 MessageBox("你按了左方向键");
      

  6.   

    楼主的意思是不是想程序一运行时不显示对话框, 当按下键盘上的某个键时才显示对话框?(对话框还没有显示出来. 当然也捕捉不到 KeyDown 和 KeyUp 消息了, 这时要通过注册一个热键来解决....)
      

  7.   

    哦?小弟的问题已解决,但还有一事不明:为什么对话框不能直接处理KEYDOWN的?而MainFrame 里可以?