Capturing ctrl keys in form KeyDown

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am trying to capture Ctrl-C/X/V in a form's KeyDown event and am using the
below code but it is not working as pressing Ctrl-C for example returns a
e.KeyCode = CtrlKey and not Keys.C, Keys.X, Keys.V etc.

Select Case e.KeyCode
Case Keys.C
If e.Modifiers = Keys.Control Then

End If
Case Keys.X
If e.Modifiers = Keys.Control Then

End If
Case Keys.V
If e.Modifiers = Keys.Control Then

End If
End Select

How can I achieve this please?

Many Thanks

Regards
 
John said:
Hi

I am trying to capture Ctrl-C/X/V in a form's KeyDown event and am using the
below code but it is not working as pressing Ctrl-C for example returns a
e.KeyCode = CtrlKey and not Keys.C, Keys.X, Keys.V etc.

Select Case e.KeyCode
Case Keys.C
If e.Modifiers = Keys.Control Then

End If
Case Keys.X
If e.Modifiers = Keys.Control Then

End If
Case Keys.V
If e.Modifiers = Keys.Control Then

End If
End Select

How can I achieve this please?

Code works correctly. First I get Keys.CtrlKey, then Keys.C. That's what
I expect pressing these keys in that order.
 
John said:
Hi

I am trying to capture Ctrl-C/X/V in a form's KeyDown event and am using
the below code but it is not working as pressing Ctrl-C for example
returns a e.KeyCode = CtrlKey and not Keys.C, Keys.X, Keys.V etc.

Private Sub Form1_KeyDown(ByVal sender as System.Object, ByVal e as
System.Windows.Forms.KeyEventArgs) Handles Form1.KeyDown

If e.Control Then
Select Case e.KeyCode
Case Keys.C
Case Keys.V
Case Keys.X
End Select
End If

End Sub

I saw where you had asked if you can capture both at the same time, not
Control first? The answer is no, but it does not matter, as pushing the keys
in the opposite direction does not work in any application. You have to
click the control key prior to the alpha key.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************
 
Back
Top