Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a certain key is being pressed?

I need to check if the SHIFT or CTRL keys are being pressed in my VB.net application, any ideas? (get a boolean)

like image 995
Voldemort Avatar asked Mar 31 '11 05:03

Voldemort


2 Answers

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
like image 139
OfficeAddinDev Avatar answered Sep 24 '22 11:09

OfficeAddinDev


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
like image 24
alldayremix Avatar answered Sep 24 '22 11:09

alldayremix