How to determine if the SHIFT or CTRL key was pressed when launching the application

slayernoah picture slayernoah · Mar 18, 2014 · Viewed 16.4k times · Source

I need to be able to determine if the SHIFT or CTRL keys were pressed when the application is launched

How can I do this for a Windows Forms Application?

Answer

ɐsɹǝʌ ǝɔıʌ picture ɐsɹǝʌ ǝɔıʌ · Mar 18, 2014

Not sure if this is what you are looking for. The following will return True or False depending on whether the key is pressed

My.Computer.Keyboard.CtrlKeyDown
My.Computer.Keyboard.ShiftKeyDown 

Example

    If My.Computer.Keyboard.CtrlKeyDown Or My.Computer.Keyboard.ShiftKeyDown Then
        MsgBox("SHIFT or CTRL key down")
    End If

If you are asking about event handling, KeyEventArgs Class is needed. Here you can view some examples how to detect shift/ctrl keypress