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
2009-10-07 21:28:39
+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
2009-10-07 21:44:35
why do you need to override? is it not possible to just add an event handler to the keydown event?
Grant
2009-10-07 22:01:29
Yes, you can do the same in an event handler
Thomas Levesque
2009-10-07 23:21:52
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
2009-10-07 23:43:28