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. Visual Basic
  4. Protected Overrides Function ProcessCmdKey

Protected Overrides Function ProcessCmdKey

Scheduled Pinned Locked Moved Visual Basic
helpquestion
9 Posts 4 Posters 1 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.
  • A Offline
    A Offline
    AndyASPVB
    wrote on last edited by
    #1

    Hi I just need some help to refine some code I am writing inside the function above in Windows form, which includes a web browser control. In my code so far I have written if msg.WParam = keys.controlkey then return true. Now this works fine, but what I am really trying to do is capture key combinations, like control & c. So, I changed it and said if msg.WParam = keys.controlkey And msg.WParam = keys.c then return true. Unfortunately, it is only capturing the control key, and if I change it to an OR then it only captures the c, which is not what I want. Is there a quick way to get both at the same time? I am not looking for lots of complicated code, just something neat and simple.

    L 1 Reply Last reply
    0
    • A AndyASPVB

      Hi I just need some help to refine some code I am writing inside the function above in Windows form, which includes a web browser control. In my code so far I have written if msg.WParam = keys.controlkey then return true. Now this works fine, but what I am really trying to do is capture key combinations, like control & c. So, I changed it and said if msg.WParam = keys.controlkey And msg.WParam = keys.c then return true. Unfortunately, it is only capturing the control key, and if I change it to an OR then it only captures the c, which is not what I want. Is there a quick way to get both at the same time? I am not looking for lots of complicated code, just something neat and simple.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, msg.WParam cannot have two different values at the same time. you can get the instantaneous value of the modifier keys through Control.ModifierKeys, so check that together with msg.WParam==(int)'c' :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


      A 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, msg.WParam cannot have two different values at the same time. you can get the instantaneous value of the modifier keys through Control.ModifierKeys, so check that together with msg.WParam==(int)'c' :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


        A Offline
        A Offline
        AndyASPVB
        wrote on last edited by
        #3

        Hi Thanks for your reply. But can you give me an example of some code, because I am unclear on how to piece it together. Thanks

        L P 2 Replies Last reply
        0
        • A AndyASPVB

          Hi Thanks for your reply. But can you give me an example of some code, because I am unclear on how to piece it together. Thanks

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I'd rather not. My VB isn't fluent and will confuse rather than help you. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


          1 Reply Last reply
          0
          • A AndyASPVB

            Hi Thanks for your reply. But can you give me an example of some code, because I am unclear on how to piece it together. Thanks

            P Offline
            P Offline
            paas
            wrote on last edited by
            #5

            If you are trying to capture the Ctrl Key plus an alpha char, like 'C', in ProcessCmdKey I believe the following will work:

             If keyData = (Keys.Control + Keys.C) Then
                ' whatever
                Return True
             End If
            

            In this case the keyData parameter is handier than the message parameter.

            A H 2 Replies Last reply
            0
            • P paas

              If you are trying to capture the Ctrl Key plus an alpha char, like 'C', in ProcessCmdKey I believe the following will work:

               If keyData = (Keys.Control + Keys.C) Then
                  ' whatever
                  Return True
               End If
              

              In this case the keyData parameter is handier than the message parameter.

              A Offline
              A Offline
              AndyASPVB
              wrote on last edited by
              #6

              Hi Thanks for your advice I tried it and it skipped over the if statement. In debug mode I hovered over the keyData variable and its value was 131089, whereas keys.control was 131072 and C was 67. Therefore, it will never equate to true. Also I noticed that won't work because the function is fired twice, which must be because there is two key strokes? Does anyone have any ideas?

              P 1 Reply Last reply
              0
              • A AndyASPVB

                Hi Thanks for your advice I tried it and it skipped over the if statement. In debug mode I hovered over the keyData variable and its value was 131089, whereas keys.control was 131072 and C was 67. Therefore, it will never equate to true. Also I noticed that won't work because the function is fired twice, which must be because there is two key strokes? Does anyone have any ideas?

                P Offline
                P Offline
                paas
                wrote on last edited by
                #7

                AndyASPVB wrote:

                Also I noticed that won't work because the function is fired twice, which must be because there is two key strokes?...

                Have you tried running the code without stepping through the debugger? I believe ProcessCmdKey may fire twice under this scenario with the first firing showing keyData as the modifier key values summed (e.g., Keys.Control + Keys.ControlKey), and the second firing being, from my code example (Keys.Control + Keys.C). At any rate, I know the sample I gave you works for me with VS 2003 or VS 2005 for capturing modifier key combinations in ProcessCmdKey (whether it be Alt or CTRL with another key). If it really is not working for you, I'm sorry I don't know why. I have not tried this under VS 2008 and, if that is what you are working under, maybe there is some slightly different behavior.

                A 1 Reply Last reply
                0
                • P paas

                  AndyASPVB wrote:

                  Also I noticed that won't work because the function is fired twice, which must be because there is two key strokes?...

                  Have you tried running the code without stepping through the debugger? I believe ProcessCmdKey may fire twice under this scenario with the first firing showing keyData as the modifier key values summed (e.g., Keys.Control + Keys.ControlKey), and the second firing being, from my code example (Keys.Control + Keys.C). At any rate, I know the sample I gave you works for me with VS 2003 or VS 2005 for capturing modifier key combinations in ProcessCmdKey (whether it be Alt or CTRL with another key). If it really is not working for you, I'm sorry I don't know why. I have not tried this under VS 2008 and, if that is what you are working under, maybe there is some slightly different behavior.

                  A Offline
                  A Offline
                  AndyASPVB
                  wrote on last edited by
                  #8

                  Yes, I am working under VS 2008. And what I wrote was in debugger mode and this is what was happening. When I switch off debugger, and just run it, nothing fires. I know nothing is firing because nested inside the if statement is a messagebox with a little message. Could the type of machine the code is running have any influence?

                  1 Reply Last reply
                  0
                  • P paas

                    If you are trying to capture the Ctrl Key plus an alpha char, like 'C', in ProcessCmdKey I believe the following will work:

                     If keyData = (Keys.Control + Keys.C) Then
                        ' whatever
                        Return True
                     End If
                    

                    In this case the keyData parameter is handier than the message parameter.

                    H Offline
                    H Offline
                    HowitZer26
                    wrote on last edited by
                    #9

                    Thanks this worked for me in c++ to be able to enabling panning with arrow keys. Holding ctrl at the same time enables micro panning.

                    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