I want to intercept the keys that are pressed when one of my dialogs is displayed
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.
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.
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With