Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Capturing "Delete button down" from keyboard

Capturing "Delete button down" from keyboard

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H harsh_2961

    Hi, Can you please tell me how to capture keyboard button down . i want especially for delete button. This is required for me because i should be able to delete selected item by pressing "Delete" or(And) "Del" button of keyboard. Harsha

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    Can you use of WM_KEYDOWN/WM_KEYUP


    WhiteSky


    L 1 Reply Last reply
    0
    • H Hamid Taebi

      Can you use of WM_KEYDOWN/WM_KEYUP


      WhiteSky


      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      Hello, can be "PretranslateMessage(MSG* pMsg)" solution for this question? Something like this:

      BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
      {
      if(pMsg->message == WM_KEYDOWN)
      {
      if(pMsg->wParam == VK_DELETE)
      {
      // do something, delete?
      }
      }
      return CDialog::PreTranslateMessage(pMsg);
      }

      regards break;

      H H 2 Replies Last reply
      0
      • L Lost User

        Hello, can be "PretranslateMessage(MSG* pMsg)" solution for this question? Something like this:

        BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
        {
        if(pMsg->message == WM_KEYDOWN)
        {
        if(pMsg->wParam == VK_DELETE)
        {
        // do something, delete?
        }
        }
        return CDialog::PreTranslateMessage(pMsg);
        }

        regards break;

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #4

        Your answer is Yes;),but you must know one thing about WM_KEY*.if you have a control on your forum then you dont get any WM_KEY* because focus send to it control.Test this sibject with a dialog that first it has controls on itself again it doesnt have any control and see retuslt.


        WhiteSky


        L 2 Replies Last reply
        0
        • H Hamid Taebi

          Your answer is Yes;),but you must know one thing about WM_KEY*.if you have a control on your forum then you dont get any WM_KEY* because focus send to it control.Test this sibject with a dialog that first it has controls on itself again it doesnt have any control and see retuslt.


          WhiteSky


          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          ok, :) what is the right way to do this? do you know some example for this? tanks break;

          1 Reply Last reply
          0
          • H Hamid Taebi

            Your answer is Yes;),but you must know one thing about WM_KEY*.if you have a control on your forum then you dont get any WM_KEY* because focus send to it control.Test this sibject with a dialog that first it has controls on itself again it doesnt have any control and see retuslt.


            WhiteSky


            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            I found this function here: ON_WM_KEYDOWN() to use with: OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) is that maybe te current way to catch key input?

            H 1 Reply Last reply
            0
            • L Lost User

              I found this function here: ON_WM_KEYDOWN() to use with: OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) is that maybe te current way to catch key input?

              H Offline
              H Offline
              harsh_2961
              wrote on last edited by
              #7

              Hi, i used the below function on WM_KEYDOWN() message, but donno why it is not working. It is not even detecting if i press any key. i dont know if ishould add something else. Note:in the function "dummy" i have a messagebox to see if its working. void CKeyboard1Dlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { //char lsChar; //lsChar=char(nChar); switch(nChar) { case VK_DELETE: dummy(); break; default: CString d1; d1="ur code not worki"; MessageBox(d1); } CDialog::OnKeyDown(nChar, nRepCnt, nFlags); } and function prototype i used is in ".h"file is "afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);" Harsha

              L H 2 Replies Last reply
              0
              • H harsh_2961

                Hi, i used the below function on WM_KEYDOWN() message, but donno why it is not working. It is not even detecting if i press any key. i dont know if ishould add something else. Note:in the function "dummy" i have a messagebox to see if its working. void CKeyboard1Dlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { //char lsChar; //lsChar=char(nChar); switch(nChar) { case VK_DELETE: dummy(); break; default: CString d1; d1="ur code not worki"; MessageBox(d1); } CDialog::OnKeyDown(nChar, nRepCnt, nFlags); } and function prototype i used is in ".h"file is "afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);" Harsha

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                Hi, have you add ON_WM_KEYDOWN() to your message map! :rolleyes: break;

                H 1 Reply Last reply
                0
                • H harsh_2961

                  Hi, i used the below function on WM_KEYDOWN() message, but donno why it is not working. It is not even detecting if i press any key. i dont know if ishould add something else. Note:in the function "dummy" i have a messagebox to see if its working. void CKeyboard1Dlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { //char lsChar; //lsChar=char(nChar); switch(nChar) { case VK_DELETE: dummy(); break; default: CString d1; d1="ur code not worki"; MessageBox(d1); } CDialog::OnKeyDown(nChar, nRepCnt, nFlags); } and function prototype i used is in ".h"file is "afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);" Harsha

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  Do you have any controls on the forum?


                  WhiteSky


                  1 Reply Last reply
                  0
                  • L Lost User

                    Hi, have you add ON_WM_KEYDOWN() to your message map! :rolleyes: break;

                    H Offline
                    H Offline
                    harsh_2961
                    wrote on last edited by
                    #10

                    Ya .. i have added on_wm_keydown().. its not worki even then. Harsha

                    1 Reply Last reply
                    0
                    • L Lost User

                      Hello, can be "PretranslateMessage(MSG* pMsg)" solution for this question? Something like this:

                      BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
                      {
                      if(pMsg->message == WM_KEYDOWN)
                      {
                      if(pMsg->wParam == VK_DELETE)
                      {
                      // do something, delete?
                      }
                      }
                      return CDialog::PreTranslateMessage(pMsg);
                      }

                      regards break;

                      H Offline
                      H Offline
                      harsh_2961
                      wrote on last edited by
                      #11

                      this code is working.. thanks a lot:) Harsha

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups