Reputation: 18149
I need to check if the SHIFT or CTRL keys are being pressed in my VB.net application, any ideas? (get a boolean)
Upvotes: 9
Views: 46602
Reputation: 753
If Control.ModifierKeys = Keys.Shift Or Control.ModifierKeys = Keys.Control Then
' Shift, Ctrl, or Shift+Ctrl is being pressed
Else
' Neither Shift nor Ctrl is being pressed
End If
Upvotes: 5
Reputation: 1125
The following will return True or False depending on whether the key is pressed at that moment. From the wording of your question, I assume you are not asking about event handling, which is what the other answers have addressed.
My.Computer.Keyboard.ShiftKeyDown
My.Computer.Keyboard.CtrlKeyDown
Upvotes: 28
Reputation: 8826
I assume you want to see on whole application. To do this, forms or controls have "keypress" or "keydown" events. You can check them with those events. Click events tab and you'll see them
Upvotes: 2
Reputation: 652
Check that link : http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.aspx#
It's about KeyEventArgs Class with some examples how to detect shift/ctrl keypress etc.
Upvotes: 0