Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't detect ESC key, MFC

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
0
0
US
I can't seem to be able to detect the escape key. I have an MFC app. I over-rode just about every key press message handler in my class object that has the input focus and none of the handlers can detect the ESC key. I can detect most other keys with the handlers I've tried. Any ideas?
 
Have you used PreTranslateMessage? If that does not work you can use a timer and call GetAsyncKeyState.


-Chris (Consultant / Software Engineer)
 
I tried pretranslate message, but during debug, I noticed that the pretranslate message function doesn't even get called.

I'll give GetAsyncKeyState a try although I try to avoid timers as much as possible.
 
The escape key is Ascii code 27. the ON_WM_CHAR() (OnChar) will detect it's input. In the OnChar member function put something like:

if ((char)nChar == (char)(27))
{
escape program.
}

-Bones
 
yeah I too used in Win32 dialog box as (on SDK)
....
case WM_KEYDOWN:
if (char(wParam)==27)
EndDialog(hDlg, 0);
break;
 
None of the above has worked. The OnChar() handler isn't being called when I press the ESC key. I've tried just about every handler including PreTranslateMessage() and nothing catches the ESC key. I'd hate to use GetAsyncKeyState() if I don't have to. Any ideas? Thanks again.
 
What type of application are you using. Is it dialog based / views ?

Also, Just check out whether you have assigned ESC key for accelerators ?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top