我想用键盘钩子,获取ctrl+1(即同时按下ctrl键和数字1键)这种按键状态,怎么做?我知道在VB中使用VK_CONTROL|VK_1来作为判断条件,但是现在该怎么做?

解决方案 »

  1.   

    LRESULT CALLBACK KeyboardProc(int code,         // hook code
                                  WPARAM wParam,    // virtual-key code
                                  LPARAM lParam)    // keystroke-message information
    {
        if (code == HC_ACTION)
        {
            // If this is a key up, or the Alt key is down, bail out now.
            if (!(lParam & 0xA0000000))
            {
    if(::GetKeyState(VK_CONTROL) < 0)//Ctrl键按下
    {
    if(wParam==0x31)//数字1
    {

    }
    }
    }
       }
    }
      

  2.   

    RegisterHotKey(m_hWnd,0xa101,MOD_CONTROL,VK_1);
    ......
    BOOL MainDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa101)
    {
    //do Ctrl+1 Process
    }
             return CDialog::PreTranslateMessage(pMsg); 
    }
    ......
    UnregisterHotKey(this->m_hWnd,0xa101);