views:

757

answers:

3

hi, is there a way to get a standard winform app to detect if the shift key is being held down on application startup - without using windows hooks? I ideally would like the workflow to change from normal if the shift key is held down when the exe is run.

A: 

Here is an article about reading the key states (and mouse) directly.

plinth
+2  A: 

Check Control.ModifierKeys ...

    [STAThread]
    static void Main(string[] args)
    {
        if (Control.ModifierKeys == Keys.ShiftKey)
        {
            // Do something special
        }
    }
Jamie Ide
Anyone care to explain why they downvoted my answer?
Jamie Ide
+3  A: 

The ModifierKeys property looks ideal:

private void Form1_Load(object sender, EventArgs e)
{
    if ( (ModifierKeys & Keys.Shift) != 0)
    {
      MessageBox.Show("Shift is pressed");
    }
}
Dan