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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard events....

Status
Not open for further replies.

SuperTeone

Programmer
Jun 25, 2001
6
IT
Hi everybody,
anyone knows how to capture a Keyboard event occurring in a dialog (that has, obviously, the focus)?? The "OnKeyDown", "OnKeyPress", ecc... work only if you are in an EditBox. They do nothing when you give the focus to something that is not
a text box or similar.

I don't want to use "GetKeyboardState" or whatever command that
requires a polling on the Keyboard status (like a typical "while"). I need to intercept the event.

Thank you very much,
bye.
Matteo.

 
Hi

If a window got the focus, it traps all the keyboard message.
So the solution is to use the PreTranslateMessage function.

Here is a typical use:

BOOL CFoo::preTranslateMessage(MSG* pMsg)
{

// Select Only WM_KEYDOWN Message

if ( pMsg->message == WM_KEYDOWN)
{
// Select ESC and Enter Key

if (( pMsg->wParam == VK_RETURN) || ( pMsg->wParam == VK_ESCAPE))
return TRUE;
}

return CDialog::preTranslateMessage(pMsg);
}


The function PreTranslateMessage can be used by the class that received the message to translate the message before they are dispatched to the controls. This gives the opportunity to the class to trap the message as, when the function returns TRUE, the message is not dispatched.

In this case, it is use to avoid getting out of a dialog box when the user presses the ESC or the RETURn key

HTH

Thierry
EMail: Thierry.Marneffe@swing.be
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top