CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2003
    Location
    Mexico City
    Posts
    6

    Smile KEYUP and KEYDOWN EVENT

    Please, i need help!!

    I have an MFC dialog based application, it has a dialog with some edit controls, i need to know when the user press an "enter key" or an "arrow up" or an "arrow down" in a specific edit control. I suposse i have to use the OnKeyUp event, but I don´t know how to do it, when i search this message in the classwizard i didn't find it
    Does anybody have an example?

    I hope you understand my english, thanks anyway!!

    Saludos
    Aida

  2. #2
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658
    You can 1) subclass the edit control or 2) use PreTranslateMessage to capture the keypress.
    PHP Code:
    BOOL CWinCvtDlg::PreTranslateMessage(MSG *pMsg)
    {
        
    /*++
         If delete key is hit, and the window
         that has focus is the is the listctrl,
         call the default delete item function
        --*/
        
    if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DELETE && pMsg->hwnd == m_FileListCtrl.GetSafeHwnd())
        {
            
    OnBtnRemove();
            return 
    TRUE// handled...
        
    }

        return 
    CDialog::PreTranslateMessage(pMsg);

    That's a function I wrote a bit back, figured it might help. It caputres key down and sees if the window that received the press was the same window as my list ctrl, and if it was it triggered the OnBtnRemoved function, otherwise it let the CDialog do as it needed
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at this FAQ for further information on the topic...

  4. #4
    Join Date
    May 2003
    Location
    Mexico City
    Posts
    6

    Wink

    Thanks a lot! That really works

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    What works? PreTranslateMessage? MFC experts don't use it because they know easier ways to do it. See the CodeGuru article for the solutions used by MFC experts.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    May 2003
    Location
    Mexico City
    Posts
    6

    ?

    Hi!

    Dou you mean that i shouldn't use Pretranslate messages???
    Why?
    Dou yo have the link for the article that you mentioned???

    TKS

  7. #7
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658
    Yeah there is a better way of doing the OK button, described in the FAQ that Andreas posted to you earlier. It works, yes, but it's not a real good way of doing it for your case.


    http://www.codeguru.com/forum/showth...hreadid=231075
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  8. #8
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: ?

    Originally posted by amoyao
    Dou yo have the link for the article that you mentioned???
    Look at the link at the bottom of the FAQ item that Andreas posted and that Eli reposted; the part just before "written by Sam Hobbs".
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #9
    Join Date
    Dec 2008
    Posts
    1

    Re: KEYUP and KEYDOWN EVENT

    Hello Everyone,

    Im developing an application in Win32. In this I have used a Custom dialog box with some buttons on it and would like to shift the focus on these based on the navigation keys from the keyboard.

    Here is the problem Im not able to catch the key down event inside the dialog box. I would appriciate some help on this.

    Thanks.

  10. #10
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: KEYUP and KEYDOWN EVENT

    Quote Originally Posted by Win32_developer View Post
    Hello Everyone,

    Im developing an application in Win32. In this I have used a Custom dialog box with some buttons on it and would like to shift the focus on these based on the navigation keys from the keyboard.

    Here is the problem Im not able to catch the key down event inside the dialog box. I would appriciate some help on this.

    Thanks.
    Why are you hijacking a 5 year old thread....Have YOU been working on theis SPECIFIC problem for the last five years????

    Ask a moderator to plit your post off to a new thread, then wait for them to do so......
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  11. #11
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: KEYUP and KEYDOWN EVENT

    I know that this latest couple of replies are nearly a month old but I have been trying since September to sign in to CodeGuru and I was unsuccessful until now.


    Quote Originally Posted by TheCPUWizard View Post
    Why are you hijacking a 5 year old thread....Have YOU been working on theis SPECIFIC problem for the last five years????
    Note that this was the first and only post by the person; I think you scared them off.

    Quote Originally Posted by TheCPUWizard View Post
    Ask a moderator to plit your post off to a new thread, then wait for them to do so......
    Or the person could create a new thread. They could post a message here when they do, so that everyone knows to answer that thread.

    Or you could suggest the person read Processing Keyboard Messages.
    Last edited by Sam Hobbs; January 14th, 2009 at 03:43 PM. Reason: syntactical clarification
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

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