Click to See Complete Forum and Search --> : Invoke certain operation through keyboard
paskal
September 14th, 1999, 01:32 PM
I wish to invoke a certain operation through keys( keyboard ). For example, I wish to delete the selected object if the user type the 'delete key'. Which is the most suitable class that will receive the message?
I'm doing on a digital circuit simulator. If I wish to delete the selected object by typing the delete key, could anyone suggest to me some relevant code. I can't find the correct code for the delete operation. In my project, I'm only using the very basic classes which are Cmainfrm, Cdocument, Cview, Class generated from the dialog box, and Capp.
Wayne Fuller
September 14th, 1999, 01:37 PM
Probably in your view class would be a good spot.
Just override OnKeyUp
void CSomeClass::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( nChar == VK_DELETE )
{
// Do something
return;
}
CSomeBaseClass::OnKeyUp(nChar, nRepCnt, nFlags);
}
Praveen
September 14th, 1999, 03:36 PM
Key press is a window's message, It can only be captured by the currently focused window. I think
view will be the best place.
Write handler for WM_KEYDOWN message.
for example to check delete key you have to check the key code against VK_DELETE so on.
there are set of defined keys in C++.
Also in this handler you can check if any of the control keys are pressed.
PRAVEEN
September 14th, 1999, 03:36 PM
Key press is a window's message, It can only be captured by the currently focused window. I think
view will be the best place.
Write handler for WM_KEYDOWN message.
for example to check delete key you have to check the key code against VK_DELETE so on.
there are set of defined keys in C++.
Also in this handler you can check if any of the control keys are pressed.
Wayne Fuller
September 14th, 1999, 03:53 PM
The problem with WM_KEYDOWN is what if somebody has a lazy finger. It is very easy to get multiple "DELETE" keys. Which is okay if you are writing an editor, but I think it would be better to use WM_KEYUP.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.