/// <summary> /// Handler for when any keyboard button is pressed. /// </summary> private void InputEvents_KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { if (Properties.Sequence.keys.Contains(e.GetDeviceKey())) { activeKey = e.GetDeviceKey(); } }
/// <summary> /// Event handler for when keys are released. /// </summary> private void InputEvents_KeyUp(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { // Skip handler if not waiting for a key-related trigger to save memory/CPU time if (!IsTriggerKeyBased(Properties.TriggerMode)) { return; } // If the pressed list contains the now released key (ensures we don't trigger on a key not in the sequence) if (_pressedKeys.Contains(e.GetDeviceKey())) { // Start animation if trigger is for 'release' event if (Properties.TriggerMode == AnimationTriggerMode.OnKeyRelease) { StartAnimation(e.GetDeviceKey()); } // Remove it from the pressed keys so it can be re-detected by the KeyDown event handler _pressedKeys.Remove(e.GetDeviceKey()); } // If we are in "while key held" mode and the user wishes to immediately terminate animations for a key when that key // is released (instead of letting the animation finish first), remove any animations assigned to the given key. if ((Properties.TriggerMode == AnimationTriggerMode.OnKeyPress || Properties.TriggerMode == AnimationTriggerMode.WhileKeyHeld) && Properties.WhileKeyHeldTerminateRunning) { runningAnimations.RemoveAll(anim => anim.assignedKey == e.GetDeviceKey()); } }
/// <summary> /// Event handler for when keys are pressed. /// </summary> private void InputEvents_KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { // Skip handler if not waiting for a key-related trigger to save memory/CPU time if (!IsTriggerKeyBased(Properties.TriggerMode)) { return; } // If triggering on any key or the pressed key is in the trigger list AND the pressed key has not already been handled (i.e. it's not being held) if ((Properties.TriggerAnyKey || Properties.TriggerKeySequence.keys.Contains(e.GetDeviceKey())) && !_pressedKeys.Contains(e.GetDeviceKey())) { // Start an animation if trigger is for 'press' event if (Properties.TriggerMode == AnimationTriggerMode.OnKeyPress) { StartAnimation(e.GetDeviceKey()); } // Mark it as handled _pressedKeys.Add(e.GetDeviceKey()); } }
private void KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { awaitingKeys.Add(e.GetDeviceKey()); }