CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Keyboard event

  1. #1
    Join Date
    Apr 1999
    Posts
    45

    Keyboard event

    I want to execute a statement when a particular key is pressed. How do I do it?

    Thank you,
    Sean.


  2. #2
    Join Date
    Apr 1999
    Location
    France
    Posts
    35

    Re: Keyboard event

    Use ClassWizard to get WM_KEYDOWN or WM_KEYUP messages.
    The method OnKeyDown will be called each time a key is down.
    Then you'll get the keycode.
    Hope it helps.


    C++ developer
    Faculté de Médecine
    27 Bd Jean Moulin
    13385 Marseille cedex 05

  3. #3
    Join Date
    Apr 1999
    Posts
    306

    Re: Keyboard event

    if you want to hook before the key override the PreTranslateMessage() function like this:

    int CDialog::PreTranslateMessage(MSG* pMsg)
    {
    if(pMsg->message==WM_KEYDOWN
    && pMsg->wParam==desired_key)
    {
    \\ execute stament
    }

    return CDialog::PreTranslateMessage(pMsg);

    }

    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured