private void _globalKeyboardHook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) { //Handle modifiers if ((e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown || e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown) && (Enum.IsDefined(typeof(KeyboardVirtualCodes), e.KeyboardData.VirtualCode))) { KeyboardVirtualCodes keyValueParsed = (KeyboardVirtualCodes)e.KeyboardData.VirtualCode; switch (keyValueParsed) { case KeyboardVirtualCodes.Alt: this._pressedOnAltLeft = true; break; case KeyboardVirtualCodes.AltGr: this._pressedOnAltRight = true; break; case KeyboardVirtualCodes.CtrlLeft: this._pressedOnCtrlLeft = true; break; case KeyboardVirtualCodes.CtrlRight: this._pressedOnCtrlRight = true; break; case KeyboardVirtualCodes.ShiftLeft: this._pressedOnShiftLeft = true; break; case KeyboardVirtualCodes.ShiftRight: this._pressedOnShiftRight = true; break; case KeyboardVirtualCodes.SuperLeft: this._pressedOnSuperLeft = true; break; case KeyboardVirtualCodes.SuperRight: this._pressedOnSuperRight = true; break; default: break; } Debug.WriteLine("Modifier ON: " + keyValueParsed.ToString() + " : " + e.KeyPressed.ToString()); //e.Handled = true; return; } //Handle modifiers if ((e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyUp || e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp) && (Enum.IsDefined(typeof(KeyboardVirtualCodes), e.KeyboardData.VirtualCode))) { KeyboardVirtualCodes keyValueParsed = (KeyboardVirtualCodes)e.KeyboardData.VirtualCode; switch (keyValueParsed) { case KeyboardVirtualCodes.Alt: this._pressedOnAltLeft = false; break; case KeyboardVirtualCodes.AltGr: this._pressedOnAltRight = false; break; case KeyboardVirtualCodes.CtrlLeft: this._pressedOnCtrlLeft = false; break; case KeyboardVirtualCodes.CtrlRight: this._pressedOnCtrlRight = false; break; case KeyboardVirtualCodes.ShiftLeft: this._pressedOnShiftLeft = false; break; case KeyboardVirtualCodes.ShiftRight: this._pressedOnShiftRight = false; break; case KeyboardVirtualCodes.SuperLeft: this._pressedOnSuperLeft = false; break; case KeyboardVirtualCodes.SuperRight: this._pressedOnSuperRight = false; break; default: break; } Debug.WriteLine("Modifier OFF: " + keyValueParsed.ToString() + " : " + e.KeyPressed.ToString()); //e.Handled = true; return; } Debug.WriteLine(e.KeyboardState.ToString() + " : " + e.KeyboardData.VirtualCode + " : " + e.KeyPressed.ToString()); if ((e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyUp || e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp)) { byte[] hello = CalculateCurrentModifierArray(); if (this._modifierArray.SequenceEqual(hello)) { IBehavior detected = null; foreach (IBehavior type in this._activeBindings) { Keys trigger = type.TriggerKey; if (e.KeyPressed == trigger) { detected = type; break; } } if (detected != null) { foreach (IBehavior type in this._activeBindings) { if (type != detected) { type.ResetModifier(); } } detected.ExecuteBehavior(); e.Handled = true; return; } } } /* * if (e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyUp) * * //Debug.WriteLine(e.KeyboardData.VirtualCode); * * if (e.KeyboardData.VirtualCode != GlobalKeyboardHook.VkSnapshot) * return; * * // seems, not needed in the life. * //if (e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown && * // e.KeyboardData.Flags == GlobalKeyboardHook.LlkhfAltdown) * //{ * // MessageBox.Show("Alt + Print Screen"); * // e.Handled = true; * //} * //else */ }
public virtual void DoStuff() { MyBehavior.ExecuteBehavior(); }