views:

359

answers:

2

Hi, does anyone know how i can setup an event handler so that if the keystrokes Alt + Shift + Ctrl + a letter will do something?

+1  A: 
override void OnKeyDown( object sender, KeyEventArgs e )
{
    bool myKeysPressed = (e.KeyCode == Keys.A) &&
                         ((e.Modifiers & Keys.Alt) == Keys.Alt) &&
                         ((e.Modifiers & Keys.Shift) == Keys.Shift) &&
                         ((e.Modifiers & Keys.Control) == Keys.Control);
}
Ed Swangren
+2  A: 

Sames as Ed's, but shorter and more readable ;)

override void OnKeyDown( object sender, KeyEventArgs e )
{
    bool myKeysPressed = (e.KeyCode == Keys.A) &&
                          e.Alt &&
                          e.Shift &&
                          e.Control;
}
Thomas Levesque
why do you need to override? is it not possible to just add an event handler to the keydown event?
Grant
Yes, you can do the same in an event handler
Thomas Levesque
Ahhh, didn't even know those properties existed.@Grant: You would override the method if this code was inside of your target object's class definition, otherwise use the event.
Ed Swangren