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

18,667

Solution 1

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

Solution 2

Alternative solution using Control.ModifierKeys:

    If Control.ModifierKeys = Keys.Shift Or Control.ModifierKeys = Keys.Control Then
        MsgBox("SHIFT or CTRL key pressed.")
    End If
Share:
18,667
slayernoah
Author by

slayernoah

SO has helped me SO much. I want to give back when I can. And I am #SOreadytohelp http://stackoverflow.com/users/1710577/slayernoah #SOreadytohelp

Updated on June 05, 2022

Comments

  • slayernoah
    slayernoah about 2 years

    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?

  • slayernoah
    slayernoah over 10 years
    Thanks a lot! Adding the above code in the Form_Load event of the start-up form enables me to achieve this.