CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Location
    Malaysia
    Posts
    60

    Invoke certain operation through keyboard

    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.








  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Invoke certain operation through keyboard

    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);
    }







  3. #3
    Join Date
    Apr 1999
    Location
    NJ, USA
    Posts
    25

    Re: Invoke certain operation through keyboard

    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.





  4. #4
    Join Date
    Apr 1999
    Location
    NJ, USA
    Posts
    25

    Re: Invoke certain operation through keyboard

    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.





  5. #5
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Invoke certain operation through keyboard

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured