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. Capture all keyboard input inside a dialog

Capture all keyboard input inside a dialog

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 5 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.
  • K Offline
    K Offline
    kevincwong
    wrote on last edited by
    #1

    Hi, I have a dialog will get input from a 2D barcode scanner, about a couple hundred characters. I already override the PreTranslateMessage but still not sure what's best way to capture the scanner input as stdin. I think my problem is that I am not too familiar with Windows messaging. So, When I got a lot messages inside PreTranslateMessage, I don't know how to filter out & convert the data I want. Can someone give me some suggestions? Thanks, Kevin

    S R A 3 Replies Last reply
    0
    • K kevincwong

      Hi, I have a dialog will get input from a 2D barcode scanner, about a couple hundred characters. I already override the PreTranslateMessage but still not sure what's best way to capture the scanner input as stdin. I think my problem is that I am not too familiar with Windows messaging. So, When I got a lot messages inside PreTranslateMessage, I don't know how to filter out & convert the data I want. Can someone give me some suggestions? Thanks, Kevin

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      I'm not sure what you're asking....Does the scanner input come in a keyboard messages? Steve

      1 Reply Last reply
      0
      • K kevincwong

        Hi, I have a dialog will get input from a 2D barcode scanner, about a couple hundred characters. I already override the PreTranslateMessage but still not sure what's best way to capture the scanner input as stdin. I think my problem is that I am not too familiar with Windows messaging. So, When I got a lot messages inside PreTranslateMessage, I don't know how to filter out & convert the data I want. Can someone give me some suggestions? Thanks, Kevin

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        kevincwong wrote:

        Capture all keyboard input inside a dialog

        You can do this by overriding PreTranslateMessage append this code inside your PreTranslateMessage handler.

        if(pMsg->message == WM_KEYDOWN)
        {
        //now the key pressed is available in
        //pMsg->wParam... store it in a string or
        //character variable and write it to a file
        }
        

        Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

        K 1 Reply Last reply
        0
        • K kevincwong

          Hi, I have a dialog will get input from a 2D barcode scanner, about a couple hundred characters. I already override the PreTranslateMessage but still not sure what's best way to capture the scanner input as stdin. I think my problem is that I am not too familiar with Windows messaging. So, When I got a lot messages inside PreTranslateMessage, I don't know how to filter out & convert the data I want. Can someone give me some suggestions? Thanks, Kevin

          A Offline
          A Offline
          Anilkumar K V
          wrote on last edited by
          #4

          Use GetWindowLong/SetWindowLong to change the Dialog proc to ur own custome made window proc. U can handle messages of ur interest, let the rest will be handled by defaultwindowproc

          1 Reply Last reply
          0
          • R Rajesh R Subramanian

            kevincwong wrote:

            Capture all keyboard input inside a dialog

            You can do this by overriding PreTranslateMessage append this code inside your PreTranslateMessage handler.

            if(pMsg->message == WM_KEYDOWN)
            {
            //now the key pressed is available in
            //pMsg->wParam... store it in a string or
            //character variable and write it to a file
            }
            

            Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

            K Offline
            K Offline
            kevincwong
            wrote on last edited by
            #5

            Rajesh, Great! that's exactly what I want. I know I read it from somewhere before but just can not remember how to do so. btw, when I pressed a key (for example 'a', the pMsg->wParm is 65, ']' is 221), I think the pMsg->wParm is the scancode (not ASCII code). Am I correct? Thank for you help!! Kevin

            J 1 Reply Last reply
            0
            • K kevincwong

              Rajesh, Great! that's exactly what I want. I know I read it from somewhere before but just can not remember how to do so. btw, when I pressed a key (for example 'a', the pMsg->wParm is 65, ']' is 221), I think the pMsg->wParm is the scancode (not ASCII code). Am I correct? Thank for you help!! Kevin

              J Offline
              J Offline
              James R Twine
              wrote on last edited by
              #6

              kevincwong wrote:

              btw, when I pressed a key (for example 'a', the pMsg->wParm is 65, ']' is 221), I think the pMsg->wParm is the scancode (not ASCII code).

              No, in the cases of the normal non-special keys, the values will be the ASCII codes for the keyboard key pressed (not the actual character received).  So when you press <A> on the keyboard, you get a value of 65, which is the same as 'A'.  This should be the code received regardless of things like SHIFT or CTRL key state.    Peace! -=- James


              If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              DeleteFXPFiles & CheckFavorites (Please rate this post!)

              K 1 Reply Last reply
              0
              • J James R Twine

                kevincwong wrote:

                btw, when I pressed a key (for example 'a', the pMsg->wParm is 65, ']' is 221), I think the pMsg->wParm is the scancode (not ASCII code).

                No, in the cases of the normal non-special keys, the values will be the ASCII codes for the keyboard key pressed (not the actual character received).  So when you press <A> on the keyboard, you get a value of 65, which is the same as 'A'.  This should be the code received regardless of things like SHIFT or CTRL key state.    Peace! -=- James


                If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                DeleteFXPFiles & CheckFavorites (Please rate this post!)

                K Offline
                K Offline
                kevincwong
                wrote on last edited by
                #7

                Hi James, That's what I guess with alphanumeric character, like 'A'. But it does not explain ']' (pMsg->Param == 221). The ASCII for for ']' is 93. It looks like 221 - 128 = 93. Do you know why? Thanks, Kevin

                J R 2 Replies Last reply
                0
                • K kevincwong

                  Hi James, That's what I guess with alphanumeric character, like 'A'. But it does not explain ']' (pMsg->Param == 221). The ASCII for for ']' is 93. It looks like 221 - 128 = 93. Do you know why? Thanks, Kevin

                  J Offline
                  J Offline
                  James R Twine
                  wrote on last edited by
                  #8

                  Hmmm!  No idea.  Maybe different local/keyboard settings than standard US-English?    Maybe using MapVirtualKeyEx(...) with a MapType of 2 would help here?    Peace! -=- James


                  If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  DeleteFXPFiles & CheckFavorites (Please rate this post!)

                  1 Reply Last reply
                  0
                  • K kevincwong

                    Hi James, That's what I guess with alphanumeric character, like 'A'. But it does not explain ']' (pMsg->Param == 221). The ASCII for for ']' is 93. It looks like 221 - 128 = 93. Do you know why? Thanks, Kevin

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    Hi Kevin, When some key is pressed, the value that arrives at

                    pMsg->wParam
                    

                    will be equal to the Virtual Key code of that particular key. Please look up MSDN for more details about Virtual Key Codes. Say, for example, when the 'p' key is pressed, the value that arrives will be equal to

                    VK_P
                    

                    which is the virtual key code of that key. If you need to know upper/lowercase detail too, use the

                    GetKeyState()
                    

                    function to know if shift key is pressed or if CAPS LOCK is turned on. Please let me know if this solved your problem. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                    K 1 Reply Last reply
                    0
                    • R Rajesh R Subramanian

                      Hi Kevin, When some key is pressed, the value that arrives at

                      pMsg->wParam
                      

                      will be equal to the Virtual Key code of that particular key. Please look up MSDN for more details about Virtual Key Codes. Say, for example, when the 'p' key is pressed, the value that arrives will be equal to

                      VK_P
                      

                      which is the virtual key code of that key. If you need to know upper/lowercase detail too, use the

                      GetKeyState()
                      

                      function to know if shift key is pressed or if CAPS LOCK is turned on. Please let me know if this solved your problem. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                      K Offline
                      K Offline
                      kevincwong
                      wrote on last edited by
                      #10

                      Got it! Thanks, Kevin

                      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