Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle a key press in MFC?

I want to intercept the keys that are pressed when one of my dialogs is displayed

like image 772
Casebash Avatar asked Dec 04 '10 07:12

Casebash


People also ask

How do I find a pressed key?

To detect keypress, we will use the is_pressed() function defined in the keyboard module. The is_pressed() takes a character as input and returns True if the key with the same character is pressed on the keyboard.

When KeyPress Event occur?

The KeyPress event is used in the Windows Form when a user presses a character, space, or backspace key during the focus on the control, the KeyPress event occurs. Furthermore, the keypress event is raised only when printable keys or numbers such as alphabets (a, b, c) are processed with Windows Form.

What is key press in keyboard?

A Press key building block is used to press and hold a key on the keyboard. This can be useful for instance when needing to hold down a CTRL key and drag the mouse. It is typically used in combination with the Release key block.

What is Event key?

An event key is used to determine whether an event is new, ongoing but changed, ongoing and unchanged, or ceased. IBM® Cognos® Event Studio compares the event instances detected in each agent run with those detected in the previous run.


1 Answers

Either set up some accelerators that send the relevant WM_COMMAND or respond to WM_KEYDOWN/UP messages and look out for your key presses.

More info here:

http://www.codeproject.com/KB/dialog/pretransdialog01.aspx

And the useful code from that article:

BOOL CPreTransTestDlg::PreTranslateMessage(MSG* pMsg) 
{
    if(pMsg->message==WM_KEYDOWN)
    {
        if(pMsg->wParam==VK_RETURN)
            pMsg->wParam=VK_TAB;
    }   
    return CDialog::PreTranslateMessage(pMsg);
}
like image 200
Goz Avatar answered Sep 25 '22 17:09

Goz