1

How do I check if Control + Z is being pressed? I managed to check for when one key is being pressed, but apparently I can't check for two at the same time.

1 Answer 1

3

Trap KeyDown event:

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  If ((e.KeyCode = Keys.Z) AndAlso e.Control) Then
    (do what you need)
  End If
End Sub
3
  • 1
    I'd probably use AndAlso instead: If e.Control AndAlso e.KeyCode = Keys.Z Then Apr 10, 2011 at 20:49
  • @Omega, @Scott: edited changing And to AndAlso. Thanks Scott.
    – Marco
    Apr 10, 2011 at 20:53
  • Works beautifully. Thank you.
    – Saturn
    Apr 10, 2011 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.