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. keyboard key event

keyboard key event

Scheduled Pinned Locked Moved C / C++ / MFC
questiondesign
28 Posts 4 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.
  • R Offline
    R Offline
    Ram Murali
    wrote on last edited by
    #1

    Hi all, In my design, i should display the individual character which are keyed in by the user into the combobox. lets say user need to key in the word "HELLO" in the combobox. if the user press "H", one message box should show the letter "H". the same way for all other letters. So, How do i get the individual character which has been keyed in using the keyboard? Thanks in Advance. Regards, Ram

    S N 2 Replies Last reply
    0
    • R Ram Murali

      Hi all, In my design, i should display the individual character which are keyed in by the user into the combobox. lets say user need to key in the word "HELLO" in the combobox. if the user press "H", one message box should show the letter "H". the same way for all other letters. So, How do i get the individual character which has been keyed in using the keyboard? Thanks in Advance. Regards, Ram

      S Offline
      S Offline
      see me
      wrote on last edited by
      #2

      :) handle ON_WM_KEYDOWN. You can get information about which key is pressed by user. :) "Dream bigger...Do bigger...Expect smaller" aji

      R 1 Reply Last reply
      0
      • S see me

        :) handle ON_WM_KEYDOWN. You can get information about which key is pressed by user. :) "Dream bigger...Do bigger...Expect smaller" aji

        R Offline
        R Offline
        Ram Murali
        wrote on last edited by
        #3

        Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it. Thanx. Regards, Ram

        T 1 Reply Last reply
        0
        • R Ram Murali

          Hi all, In my design, i should display the individual character which are keyed in by the user into the combobox. lets say user need to key in the word "HELLO" in the combobox. if the user press "H", one message box should show the letter "H". the same way for all other letters. So, How do i get the individual character which has been keyed in using the keyboard? Thanks in Advance. Regards, Ram

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          When u press a key in the combobox the message actually goes to the edit control inside the combo box. To trap that event u can do like this. 1 Create a member variable for the combobox say m_ComboBox; 2. Now overide the PreTranslateMessage function of the dialog; 3. in that funtion write like this BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CDialog::PreTranslateMessage(pMsg); } nave

          R 1 Reply Last reply
          0
          • N Naveen

            When u press a key in the combobox the message actually goes to the edit control inside the combo box. To trap that event u can do like this. 1 Create a member variable for the combobox say m_ComboBox; 2. Now overide the PreTranslateMessage function of the dialog; 3. in that funtion write like this BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CDialog::PreTranslateMessage(pMsg); } nave

            R Offline
            R Offline
            Ram Murali
            wrote on last edited by
            #5

            if i do this, i couldnt able to get the output. the project is comiled and exectued, but there is no output and comeback to the project workspace again. Y is it like this? Thanks. Regards, Ram

            N 1 Reply Last reply
            0
            • R Ram Murali

              if i do this, i couldnt able to get the output. the project is comiled and exectued, but there is no output and comeback to the project workspace again. Y is it like this? Thanks. Regards, Ram

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              what type of application did u created? Dialog based? nave

              R 1 Reply Last reply
              0
              • N Naveen

                what type of application did u created? Dialog based? nave

                R Offline
                R Offline
                Ram Murali
                wrote on last edited by
                #7

                yes,My application is dialog based. it has only one combobox, nothing more than that. Jus i need to display the characters which has been key-in by the user into the combobox. Regards, Ram

                N 1 Reply Last reply
                0
                • R Ram Murali

                  Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it. Thanx. Regards, Ram

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  Ram Murali wrote:

                  Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it.

                  have you added that between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                  R 1 Reply Last reply
                  0
                  • R Ram Murali

                    yes,My application is dialog based. it has only one combobox, nothing more than that. Jus i need to display the characters which has been key-in by the user into the combobox. Regards, Ram

                    N Offline
                    N Offline
                    Naveen
                    wrote on last edited by
                    #9

                    i hope u have created the m_combo variable and mapped the PreTranslateMessage message using the class wizard. isn't it? did u tried puting breakpoint in the PreTranslateMessage fnuction? nave

                    R 1 Reply Last reply
                    0
                    • T ThatsAlok

                      Ram Murali wrote:

                      Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it.

                      have you added that between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                      R Offline
                      R Offline
                      Ram Murali
                      wrote on last edited by
                      #10

                      Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP. Regards, Ram

                      T 1 Reply Last reply
                      0
                      • N Naveen

                        i hope u have created the m_combo variable and mapped the PreTranslateMessage message using the class wizard. isn't it? did u tried puting breakpoint in the PreTranslateMessage fnuction? nave

                        R Offline
                        R Offline
                        Ram Murali
                        wrote on last edited by
                        #11

                        Ya u r correct. I used breakpoint also. Still i couldnt get the output window. I put breakpoint in OnInitDialog and PreTranslateMessage. once i press debug button, it directly goes to pretanslatemessage function and then goes to the end of the program. since i dun input any char if( WM_KEYDOWN == pMsg->message ) becomes false. so it goes to the end of the pretanslate function. in this case i can see the minimized window in the taskbar. but i couldnt maximize it. eventually i couldnt see the output window. :( Regards, Ram

                        N 1 Reply Last reply
                        0
                        • R Ram Murali

                          Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP. Regards, Ram

                          T Offline
                          T Offline
                          ThatsAlok
                          wrote on last edited by
                          #12

                          Ram Murali wrote:

                          Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.

                          Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program

                          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                          cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                          R N 2 Replies Last reply
                          0
                          • T ThatsAlok

                            Ram Murali wrote:

                            Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.

                            Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program

                            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                            R Offline
                            R Offline
                            Ram Murali
                            wrote on last edited by
                            #13

                            :(Yes i did that too. Regards, Ram

                            1 Reply Last reply
                            0
                            • R Ram Murali

                              Ya u r correct. I used breakpoint also. Still i couldnt get the output window. I put breakpoint in OnInitDialog and PreTranslateMessage. once i press debug button, it directly goes to pretanslatemessage function and then goes to the end of the program. since i dun input any char if( WM_KEYDOWN == pMsg->message ) becomes false. so it goes to the end of the pretanslate function. in this case i can see the minimized window in the taskbar. but i couldnt maximize it. eventually i couldnt see the output window. :( Regards, Ram

                              N Offline
                              N Offline
                              Naveen
                              wrote on last edited by
                              #14

                              will u plz paste the PreTranslateMessage funtion here. nave

                              R 1 Reply Last reply
                              0
                              • T ThatsAlok

                                Ram Murali wrote:

                                Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.

                                Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program

                                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                                N Offline
                                N Offline
                                Naveen
                                wrote on last edited by
                                #15

                                ThatsAlok wrote:

                                OnKeyDown

                                r u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox. It cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox nave

                                T 1 Reply Last reply
                                0
                                • N Naveen

                                  will u plz paste the PreTranslateMessage funtion here. nave

                                  R Offline
                                  R Offline
                                  Ram Murali
                                  wrote on last edited by
                                  #16

                                  BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CTest::PreTranslateMessage(pMsg); } Regards, Ram

                                  N 1 Reply Last reply
                                  0
                                  • R Ram Murali

                                    BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CTest::PreTranslateMessage(pMsg); } Regards, Ram

                                    N Offline
                                    N Offline
                                    Naveen
                                    wrote on last edited by
                                    #17

                                    Ram Murali wrote:

                                    return CTest::PreTranslateMessage(pMsg);

                                    here lies the problem it should be like this CDialog::PreTranslateMessage(pMsg); nave

                                    R 1 Reply Last reply
                                    0
                                    • N Naveen

                                      Ram Murali wrote:

                                      return CTest::PreTranslateMessage(pMsg);

                                      here lies the problem it should be like this CDialog::PreTranslateMessage(pMsg); nave

                                      R Offline
                                      R Offline
                                      Ram Murali
                                      wrote on last edited by
                                      #18

                                      wow. thats gr8. But now i can able to key-in only one character. cannot key-in more than one char.:( Thanx for spending ur time for me. Thanx a lot. Regards, Ram

                                      N T 2 Replies Last reply
                                      0
                                      • R Ram Murali

                                        wow. thats gr8. But now i can able to key-in only one character. cannot key-in more than one char.:( Thanx for spending ur time for me. Thanx a lot. Regards, Ram

                                        N Offline
                                        N Offline
                                        Naveen
                                        wrote on last edited by
                                        #19

                                        Ram Murali wrote:

                                        now i can able to key-in only one character.

                                        what do u mean? nave

                                        R 1 Reply Last reply
                                        0
                                        • N Naveen

                                          ThatsAlok wrote:

                                          OnKeyDown

                                          r u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox. It cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox nave

                                          T Offline
                                          T Offline
                                          ThatsAlok
                                          wrote on last edited by
                                          #20

                                          Naveen R wrote:

                                          u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox.

                                          I believe you havn't read my question carefully!, after reading your discussion with the PP(Problem Poster), i come to know he need to implement that for Combo Box!

                                          Naveen R wrote:

                                          t cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox

                                          Really do you need my comment on this?

                                          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                                          cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                                          N 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