Protected Overrides Function ProcessCmdKey
-
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.
-
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.
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
-
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
-
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
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
-
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
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.
-
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.
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?
-
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?
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.
-
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.
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?
-
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.
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.