Solved

How to trap the ESCAPE key

Posted on 1998-12-11
3
1,026 Views
Last Modified: 2013-11-20
Hello:

I'm trying to trap the escape key but unsuccessfuly.
This is what I've tried:

CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlag)
{
   if (nChar==VK_ESCAPE)
   {
        //Some code...
   }

}

However, when the escape key is pressed OnKeyDown message
is not called.

Any idea?
0
Comment
Question by:qocarlos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1326063
I don't know for sure, but is it possible that the OnKeyDown member function is not called in the view class?  Have you tried the same code in the app class (is that the term?)?
0
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1326064
You should trap the PreTranslateMessage of your view class. Here is a sample code. It works for CView as well as CFormView derived classes:
BOOL CMyView::PreTranslateMessage(MSG* pMsg)
{
      // TODO: Add your specialized code here and/or call the base class
      if(pMsg->message==WM_KEYUP){
            if(pMsg->wParam==VK_ESCAPE)
                  MessageBox("RUN");
      }
      return CFormView::PreTranslateMessage(pMsg);
}

I hope this will help. Thanks
pagladasu
0
 
LVL 3

Author Comment

by:qocarlos
ID: 1326065
pagladasu,
THANKS, it works great!
What I would like to know is why I don't get the OnKeyDown function when pressing the escape key.
Anyway, thanks again for your help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question