Getting key presses from MFC
-
I have a list control and a number of handlers. What I want is to be able to process key presses as well as mouse clicks so if I select an item and press the Delete key on the keyboard I can call my Delete button handler. I have a handler called OnKeydownMyList() which is called when I press a key. How do I find out what key has been pressed so I can call the right handler? Thank you.
-
I have a list control and a number of handlers. What I want is to be able to process key presses as well as mouse clicks so if I select an item and press the Delete key on the keyboard I can call my Delete button handler. I have a handler called OnKeydownMyList() which is called when I press a key. How do I find out what key has been pressed so I can call the right handler? Thank you.
Hi, Your OnKeyDownMyList() looks like this :
void Cxxx::OnKeyDownMyList( NMHDR* pNMHDR, LRESULT* pResult ) { LV_KEYDOWN* pLVKeyDow = ( LV_KEYDOWN* ) pNMHDR; *pResult = 0; }
Here you can use the wVKey member of the pLVKeyDow.. Example :void Cxxx::OnKeyDownMyList( NMHDR* pNMHDR, LRESULT* pResult ) { LV_KEYDOWN* pLVKeyDow = ( LV_KEYDOWN* ) pNMHDR; if( pLVKeyDow->wVKey == VK_DELETE ) { // Call the function that deletes the selected item... } *pResult = 0; }
-
Hi, Your OnKeyDownMyList() looks like this :
void Cxxx::OnKeyDownMyList( NMHDR* pNMHDR, LRESULT* pResult ) { LV_KEYDOWN* pLVKeyDow = ( LV_KEYDOWN* ) pNMHDR; *pResult = 0; }
Here you can use the wVKey member of the pLVKeyDow.. Example :void Cxxx::OnKeyDownMyList( NMHDR* pNMHDR, LRESULT* pResult ) { LV_KEYDOWN* pLVKeyDow = ( LV_KEYDOWN* ) pNMHDR; if( pLVKeyDow->wVKey == VK_DELETE ) { // Call the function that deletes the selected item... } *pResult = 0; }