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