Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. why OnKeyDown & OnKeyUp different when they meet "Enter"?

why OnKeyDown & OnKeyUp different when they meet "Enter"?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Chan 0
    wrote on last edited by
    #1

    I was writing a control "CColorEdit" which is derived from CEdit. I have override its OnKeyUp() and OnKeyDown. When I pressed the key "Enter", the OnKeyDown was invoked, but OnKeyUp wasn't invoked. I feel very confused. Does anyone have ever occured this kind of think. Waiting for answer. Best Regards.

    H 1 Reply Last reply
    0
    • P Peter Chan 0

      I was writing a control "CColorEdit" which is derived from CEdit. I have override its OnKeyUp() and OnKeyDown. When I pressed the key "Enter", the OnKeyDown was invoked, but OnKeyUp wasn't invoked. I feel very confused. Does anyone have ever occured this kind of think. Waiting for answer. Best Regards.

      H Offline
      H Offline
      Habeeballah Hasnoddin
      wrote on last edited by
      #2

      For sure you have put the messagebox code in OnKeyDown. Since the messagebox pops up in OnKeyDown, the focus is gained by the messagebox, so the OnKeyUp will not be handled on the edit box. I tested myself without the messagebox, and for me both keydown and keyup are working fine on a derived class of CEdit.

      Habeeballah Hasnoddin :rose:

      P 1 Reply Last reply
      0
      • H Habeeballah Hasnoddin

        For sure you have put the messagebox code in OnKeyDown. Since the messagebox pops up in OnKeyDown, the focus is gained by the messagebox, so the OnKeyUp will not be handled on the edit box. I tested myself without the messagebox, and for me both keydown and keyup are working fine on a derived class of CEdit.

        Habeeballah Hasnoddin :rose:

        P Offline
        P Offline
        Peter Chan 0
        wrote on last edited by
        #3

        I think my code is OK. But it still doesn't work. void CTestEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if ( nChar == 13 ) { //MessageBox("Down"); SetWindowText( "Bye Bye Bye" ); } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }

        H 1 Reply Last reply
        0
        • P Peter Chan 0

          I think my code is OK. But it still doesn't work. void CTestEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if ( nChar == 13 ) { //MessageBox("Down"); SetWindowText( "Bye Bye Bye" ); } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }

          H Offline
          H Offline
          Habeeballah Hasnoddin
          wrote on last edited by
          #4

          I got the point. ==> You must have "Multiline" and "WantReturn" properties set on this edit box. As I observed while testing, the following is true. --> If you set just the "Multiline" then only keydown gets fired and not the keyup. --> If you set just the wantreturn and not the Multiline then only keyup gets fired and not keydown. thats it.

          Habeeballah Hasnoddin

          P 1 Reply Last reply
          0
          • H Habeeballah Hasnoddin

            I got the point. ==> You must have "Multiline" and "WantReturn" properties set on this edit box. As I observed while testing, the following is true. --> If you set just the "Multiline" then only keydown gets fired and not the keyup. --> If you set just the wantreturn and not the Multiline then only keyup gets fired and not keydown. thats it.

            Habeeballah Hasnoddin

            P Offline
            P Offline
            Peter Chan 0
            wrote on last edited by
            #5

            Thank you very much. You are so kind.:-D

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups