Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping Modifier Keys 1

Status
Not open for further replies.

sacsac

Programmer
Dec 10, 2000
174
0
0
GB
I am trying to trap combinations of the ALT/SHIFT keys in the KeyDown event of a form, using this code:

Private Sub frmMDI_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown


If Control.ModifierKeys = Keys.Shift Or Control.ModifierKeys = Keys.Alt Then
'do something
End If

End Sub

This successfully traps if EITHER key is pressed. However, if in order to trap events when BOTH keys are pressed I replace the "Or" with "And", as here:

If Control.ModifierKeys = Keys.Shift And Control.ModifierKeys = Keys.Alt Then
'do something
End If

then NOTHING happens at all. What am I missing here?
 
I have resolved this myself with:

If Control.ModifierKeys = Keys.Shift + Keys.Alt + Keys.Control Then

'do something

EndIf


Simple really!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top