Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect shift key on application startup in C#/Windows Forms

Is there a way to get a standard Windows Forms application 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 file is run.

like image 423
Grant Avatar asked Nov 28 '22 19:11

Grant


1 Answers

The ModifierKeys property looks ideal:

private void Form1_Load(object sender, EventArgs e)
{
    if ( (ModifierKeys & Keys.Shift) != 0)
    {
      MessageBox.Show("Shift is pressed");
    }
}
like image 88
Dan Avatar answered Dec 19 '22 00:12

Dan