/// <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>KeyDown handler that checks the current application's profiles for keybinds. /// In the case of multiple profiles matching the keybind, it will pick the next one as specified in the Application.Profile order.</summary> public void CheckProfileKeybinds(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { ILightEvent profile = GetCurrentProfile(); // Check profile is valid and do not switch profiles if the user is trying to enter a keybind if (profile is Application && Controls.Control_Keybind._ActiveKeybind == null) { // Find all profiles that have their keybinds pressed List <ApplicationProfile> possibleProfiles = new List <ApplicationProfile>(); foreach (var prof in (profile as Application).Profiles) { if (prof.TriggerKeybind.IsPressed()) { possibleProfiles.Add(prof); } } // If atleast one profile has it's key pressed if (possibleProfiles.Count > 0) { // The target profile is the NEXT valid profile after the currently selected one (or the first valid one if the currently selected one doesn't share this keybind) int trg = (possibleProfiles.IndexOf((profile as Application).Profile) + 1) % possibleProfiles.Count; (profile as Application).SwitchToProfile(possibleProfiles[trg]); } } }
/// <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()); } }
private void InputEvents_KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { foreach (var keybind in Properties.TriggerKeys) { if (keybind.IsPressed()) { switch (Properties.RepeatAction) { // Restart the timer from scratch case TimerLayerRepeatPressAction.Reset: timer.Reset(Properties.Duration); isActive = true; break; case TimerLayerRepeatPressAction.Extend: timer.Extend(Properties.Duration); isActive = true; break; case TimerLayerRepeatPressAction.Ignore: if (!isActive) { timer.Reset(Properties.Duration); isActive = true; } break; } return; } } }
private void InputEvents_KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { foreach (var kb in Properties.TriggerKeys) { if (kb.IsPressed()) { state = !state; } } }
private static void InputEvents_KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { if (listeningEditor != null) { listeningEditor.Dispatcher.Invoke(() => { listeningEditor.SelectedKey = e.Key; listeningEditor.UpdateButtonText(false); listeningEditor = null; }); } }
/// <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 HandleKeyboardInput(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { var newKeyState = new KeyState() { CurrentState = e.State }; KeyState lastKeyState; try { if (_keysStates.TryGetValue((int)e.Key, out lastKeyState)) { newKeyState.PreviousState = lastKeyState.CurrentState; if (newKeyState.IsKeyPressed && KeyPressedEvent != null) { KeyPressedEvent(this, new KeyEventArgs(e.Key, e.State)); } if (newKeyState.IsKeyReleased && KeyReleasedEvent != null) { KeyReleasedEvent(this, new KeyEventArgs(e.Key, e.State)); } } else { if (KeyPressedEvent != null) { KeyPressedEvent(this, new KeyEventArgs(e.Key, e.State)); } } } catch (Exception exception) { Logger.Error("Handling keyboard event failed with exception: {0}", exception); } _keysStates[(int)e.Key] = newKeyState; }
private void KeyDown(object sender, SharpDX.RawInput.KeyboardInputEventArgs e) { awaitingKeys.Add(e.GetDeviceKey()); }