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. How do I know if an OK event came from mouse or Enter?

How do I know if an OK event came from mouse or Enter?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelplearning
6 Posts 4 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.
  • I Offline
    I Offline
    IlanTal
    wrote on last edited by
    #1

    How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter? The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK. I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it. Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it. Any suggestions would be appreciated. Thanks, Ilan

    W G C 4 Replies Last reply
    0
    • I IlanTal

      How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter? The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK. I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it. Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it. Any suggestions would be appreciated. Thanks, Ilan

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      I'm not quite sure how to do this in MFC, but in win32, you need to change the way the messages are handled. This code is inserted into the winMain and it checks for messages being sent to the dialog.

      while( GetMessage( &msg, NULL, 0, 0 ) )
      {
      	if(!IsDialogMessage(dlgHwnd, &msg)) {
      		TranslateMessage( &msg );
      		DispatchMessage( &msg );
      	}
      }
      
      return msg.wParam;
      
      1 Reply Last reply
      0
      • I IlanTal

        How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter? The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK. I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it. Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it. Any suggestions would be appreciated. Thanks, Ilan

        G Offline
        G Offline
        Graham Bradshaw
        wrote on last edited by
        #3

        You're going about it the wrong way, really. Take a look at the ES_WANTRETURN style for the edit box - setting that will probably give you the result you're after.

        I 1 Reply Last reply
        0
        • G Graham Bradshaw

          You're going about it the wrong way, really. Take a look at the ES_WANTRETURN style for the edit box - setting that will probably give you the result you're after.

          I Offline
          I Offline
          IlanTal
          wrote on last edited by
          #4

          Thanks Graham. This gives me EXACTLY the result I wanted. Since I never used it, I didn't know it existed. Thanks again, Ilan

          1 Reply Last reply
          0
          • I IlanTal

            How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter? The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK. I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it. Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it. Any suggestions would be appreciated. Thanks, Ilan

            C Offline
            C Offline
            Chris Gao
            wrote on last edited by
            #5

            Hi Ilan, Well, my suggestion is that you declare two time stamps and use them to keep the latest time of left mouse click and Enter key click. In OnOk functions, you may compare the current time with both time stamps and this may give you some idea about which is the source of the action. regards, chris

            1 Reply Last reply
            0
            • I IlanTal

              How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter? The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK. I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it. Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it. Any suggestions would be appreciated. Thanks, Ilan

              C Offline
              C Offline
              Chris Gao
              wrote on last edited by
              #6

              Oops, I didn't see other replys just now. Obviously, my suggestion is the worst one. hehe, ignor it. Regards, Chris

              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