我想在面板上做一个按键,当鼠标点击它就实现与在键盘上按下一个键相同的功能 怎么做

解决方案 »

  1.   

    响应这个按键消息,在消息里用keybd_event模拟键按下
      

  2.   

    发消息,比如按一"a",发WM_KEYDOWN,WM_CHAR,WM_KEYUP,用spy看一下,到底按一个"a",window要收到多少消息,全模拟
      

  3.   


    BOOL CUrDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
         if(pMsg->message==WM_KEYDOWN && pMsg->wParaw==urChar)
            {
                OnButton1();//ur button function
               return TRUE;


    return CEdit::PreTranslateMessage(pMsg);
    }
      

  4.   

    VOID C**Dlg::OnButton()
    {keybd_event(..);
    ...}
      

  5.   

    SORRY,IT'S WRONG.
    WAIT. PLZ
      

  6.   

    void CTest11Dlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    SendMessage(WM_CHAR, 'a'); 

    }void CTest11Dlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    if(nChar=='a')
    {
    AfxMessageBox("hello");
    }

    CDialog::OnChar(nChar, nRepCnt, nFlags);
    }
      

  7.   

    还要模拟button被按下的话,可以
    SendMessage(m_pParentHwnd,WM_COMMAND,MAKEWPARAM(ID_BUTTON,BN_CLICKED),(LPARAM)buttonHwnd);
      

  8.   

    // Simulate a key press
             keybd_event( VK_NUMLOCK,
                          0x45,
                          KEYEVENTF_EXTENDEDKEY | 0,
                          0 );      // Simulate a key release
             keybd_event( VK_NUMLOCK,
                          0x45,
                          KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                          0);
      

  9.   

    我做一个类似计算器的东西,按下1按钮键后我的CEDIT中显示1,以上方法好像无法实现
      

  10.   

    keybd_event里的第一个参数就是你想模拟的按键的虚拟健值
    你可以查msdn 关键字“Virtual-Key Codes”
    可以获得所有虚拟健值的信息
      

  11.   

    正确答案是:SendInput
    完全跟按下键盘按键一样,别忘了发送完按下发送放开。
      

  12.   

    SendMessage(WM_KEYDOWN,.....);
    SendMessage(WM_KEYUP,.....);
      

  13.   

    keybd_event
    This function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. VOID keybd_event( 
    BYTE bVk, 
    BYTE bScan, 
    DWORD dwFlags, 
    DWORD dwExtraInfo 
    );
    Parameters
    bVk 
    [in] Specifies a virtual-key code. The code must be a value in the range 1 to 254. 
    bScan 
    [in] Specifies a hardware scan code for the key. This parameter is not explicitly used. 
    dwFlags 
    [in] Specifies various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value Description 
    KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed. 
    KEYEVENTF_SILENT If specified, a keystroke is simulated, but no clicking sound is made. dwExtraInfo 
    [in] Specifies an additional 32-bit value associated with the key stroke. 
    Return Values
    None.Res
    When keyboard input is disabled with EnableHardwareKeyboard(FALSE), you can simulate keyboard input using keybd_event.Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications.The parameters bVk and bScan are treated independently. The OS does not use bVk to generate bScan and does not use bScan to generate bVk.An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.