Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle the KeyDown Event when ALT+KEY is Pressed

How do you handle a KeyDown event when the ALT key is pressed simultaneously with another key in .NET?

like image 608
Jedi Master Spooky Avatar asked Jan 27 '10 13:01

Jedi Master Spooky


3 Answers

The KeyEventArgs class defines several properties for key modifiers - Alt is one of them and will evaluate to true if the alt key is pressed.

like image 162
Oded Avatar answered Nov 12 '22 07:11

Oded


private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Alt && e.KeyData != (Keys.RButton | Keys.ShiftKey | Keys.Alt))
    {
        // ...
    }
}
like image 25
kor_ Avatar answered Nov 12 '22 07:11

kor_


Something like:

   private void Form1_KeyDown(object sender, KeyEventArgs e)
   {
        if (e.Alt)
        {
            e.Handled = true;
            // ,,,
        }
    }
like image 2
Henk Holterman Avatar answered Nov 12 '22 06:11

Henk Holterman