public IKeyboardCommandTrigger OnEvent(IHotkey hotkey, KeyEvent keyEvent, string stateTree = KeyStateTrees.Default) { if (keyEvent == KeyEvent.Hit) { return(OnHit(hotkey, stateTree)); } var sequence = hotkey switch { ISequenceUnit sequenceUnit => new List <ICombination>() { sequenceUnit.ToCombination().ToCombination() }, ISequence seq => seq.ToList(), _ => throw new Exception("IHotkey should be ISequence or ISequenceUnit") }; var trigger = new KeyboardCommandTrigger(); var metaKey = Add(sequence, keyEvent, new KeyCommand(trigger.OnExecute) { CanExecute = trigger.OnCanExecute }, stateTree) as MetaKey; trigger._metaKey = metaKey; return(trigger); }
public GenericHotkeyProxy(IHotkey hotkey) { if (hotkey is KeyboardHotkey kbdHotkey) { this.Type = HotkeyType.Keyboard; this.keyboardHotkey = new KeyboardHotkey(kbdHotkey); this.mouseHookHotkey = new MouseHookHotkey(hotkey); } else if (hotkey is MouseHookHotkey mhHotkey) { this.Type = HotkeyType.MouseHook; this.mouseHookHotkey = new MouseHookHotkey(mhHotkey); this.keyboardHotkey = new KeyboardHotkey(hotkey); } else { this.Type = HotkeyType.Undefined; this.keyboardHotkey = hotkey != null ? new KeyboardHotkey(hotkey) : new KeyboardHotkey(); this.mouseHookHotkey = hotkey != null ? new MouseHookHotkey(hotkey) : new MouseHookHotkey(); } App.Container.BuildUp(this.keyboardHotkey, this.mouseHookHotkey); this.keyboardHotkey.PropertyChanged += this.KeyboardHotkey_PropertyChanged; this.mouseHookHotkey.PropertyChanged += this.MouseHookHotkey_PropertyChanged; }
public static Task <IKeyEventArgs> UpAsync(this IHotkey sequenceUnit, int timeout = -1, string description = "", string stateTree = KeyStateTrees.Default) { var command = new KeyEventAsync(); sequenceUnit.OnUp(command.OnEvent, null, description, stateTree); return(command.WaitAsync(timeout)); }
/// <summary> /// register the key to the state tree, and wait the down event; /// timeout: return null /// </summary> public static Task <IKeyEventArgs> DownAsync(this IHotkey hotkey, int timeout = -1, string description = "", string stateTree = KeyStateTrees.Default) { var command = new KeyEventAsync(); hotkey.OnDown(command.OnEvent, null, description, stateTree); return(command.WaitAsync(timeout)); }
public ISequence Then(IHotkey hotkey) { var sequence = new Sequence(this); sequence.AddRange(hotkey.ToSequence()); return(sequence); }
private void CheckIfProperHotkeyType(Type t, IHotkey hk) { if (t != hk.GetType()) { throw new Exception("Invalid hotkey type"); } }
public void ModifyAudioHotkey(int hotkeyId, string newName = "", string newKey = "", string newFiles = "", float newVolume = -1, int newStartingTime = -1, string newAudioDevice = "") { IHotkey hk = FindHotkeyById(hotkeyId); CheckIfProperHotkeyType(typeof(AudioHotkey), hk); AudioHotkey hotkey = (AudioHotkey)hk; if (newName != "") { hotkey.Name = newName; } if (newKey != "") { ModifyHotkey(hotkeyId, newKey); } if (newFiles != "") { hotkey.Files = newFiles; } if (newVolume != -1) { hotkey.Volume = newVolume / 100; } if (newStartingTime != -1) { hotkey.StartingTime = newStartingTime; } if (newAudioDevice != "") { hotkey.AudioDevice = new Guid(newAudioDevice); } }
public static void Remove(IHotkey hotkey) { if (HotkeyCollection.Contains(hotkey)) { HotkeyCollection.Remove(hotkey); } }
public static void Add(IHotkey hotkey) { if (!HotkeyCollection.Contains(hotkey)) { HotkeyCollection.Add(hotkey); } }
public static IKeyCommand OnHit(this IHotkey sequenceUnit, Action <IKeyEventArgs> execute, Predicate <IKeyEventArgs> canExecute = null, string description = "", string stateTree = KeyStateTrees.Default) { var trigger = Keyboard.OnHit(sequenceUnit, stateTree); return(trigger.Register(execute, canExecute, description)); }
public IHotkey FindHotkeyById(int id) { IHotkey hk = null; hk = hotkeysList.Find(hkey => hkey.Id == id); return(hk); }
public IKeyboardCommandTrigger OnHit(IHotkey hotkey, string stateTree = KeyStateTrees.Default) { var trigger = new KeyboardCommandTrigger(); var token = Hit(hotkey, trigger.OnExecute, trigger.OnCanExecute, "", stateTree) as KeyCommandTokens; trigger._metaKey = token?.metaKey; return(trigger); }
/// <summary> /// down up happened successively /// </summary> private IKeyCommand Hit(IHotkey hotkey, Action <IKeyEventArgs> execute, Predicate <IKeyEventArgs> canExecute = null, string description = "", string stateTree = KeyStateTrees.Default) { var noEventTimer = new NoEventTimer(); // state var handling = false; IKeyEventArgs keyDownEvent = null; void Reset() { handling = false; keyDownEvent = null; } var token = new KeyCommandTokens { hotkey.OnDown(e => { handling = true; keyDownEvent = e; }, e => { var noEventDuration = noEventTimer.NoEventDuration; if (noEventDuration > StateResetTime) { Reset(); } noEventTimer.EventPulse(); return(canExecute?.Invoke(e) ?? true); }, description, stateTree), hotkey.OnUp(e => { if (!handling) { Console.WriteLine($"\t{hotkey}_Hit Down CanExecute:false"); return; } handling = false; if (keyDownEvent == e.LastKeyDownEvent) { execute(e); } else { Console.WriteLine($"\t{hotkey}_Hit: last down event is not from me, Not Execute!"); } }, canExecute, description, stateTree) }; return(token); }
// if the handler async run, this is needed. public static IHotkey Handled(this IHotkey hotkey, KeyEvent keyEvent = KeyEvent.All) { hotkey.Handled = keyEvent; // if ((keyEvent & KeyEvent.Down) == KeyEvent.Down) // hotkey.Down(e => e.Handled = true); // if ((keyEvent & KeyEvent.Up) == KeyEvent.Up) // hotkey.Up(e => e.Handled = true); // if ((keyEvent & KeyEvent.AllUp) == KeyEvent.AllUp) // hotkey.AllUp(e => e.Handled = true); return(hotkey); }
public void RemoveHotkey(int hotkeyId) { if (hotkeyId == MasterHotkey.Id) { MasterHotkey.Unregister(); } else { IHotkey hk = FindHotkeyById(hotkeyId); hk.Unregister(); hotkeysList.Remove(hk); } }
/// <summary> /// Get the shortcut string for a hotkey, if it's defined /// </summary> /// <param name="hotkey"></param> /// <returns></returns> public string GetHotkeyString(IHotkey hotkey) { if (hotkey == null) { return(null); } var keys = _registeredHotkeys.Where(x => x.Value == hotkey).Select(x => x.Key).ToList(); if (keys.Count == 0) { return(null); } return(keys.Contains(hotkey.DefaultHotkey) ? hotkey.DefaultHotkey : keys.FirstOrDefault()); }
public void ModifyHotkey(int hotkeyId, string newKey) { IHotkey hk = FindHotkeyById(hotkeyId); KeyAndModifiers newFullKey = CreateAndValidateFullKey(newKey); KeyAndModifiers oldFullKey = hk.Key; hk.Key = newFullKey; int result = hk.Reregister(); if (result != 1 && result != -3) { hk.Key = oldFullKey; hk.Register(mainFrm); CheckHotkeyResult(result, newKey); } }
public CopypastaController(IClipboard clipboard, IClipboardHistoryManager clipboardHistoryManager, IClipboardBindingManager clipboardBindingManager, IHotkey ctrlVHotkey, IHotkey ctrlCHotkey, IHotkey escHotkey, IKeyTracker keyTracker, IInputSimulator inputSimulator, INotificationDispatcher notificationDispatcher) { _clipboard = clipboard; _clipboardHistoryManager = clipboardHistoryManager; _clipboardBindingManager = clipboardBindingManager; _ctrlVHotkey = ctrlVHotkey; _ctrlCHotkey = ctrlCHotkey; _escHotkey = escHotkey; _keyTracker = keyTracker; _inputSimulator = inputSimulator; _notificationDispatcher = notificationDispatcher; _copypastaStateMachine = new StateMachine <CopypastaState, CopypastaTrigger>(CopypastaState.Idle); _keyPressedTrigger = _copypastaStateMachine.SetTriggerParameters <Key>(CopypastaTrigger.KeyPressed); ConfigureCopypastaStateMachine(); ConfigureEventTriggers(); }
internal bool Contains(IHotkey hotKey) { IEnumerable <KeyEventCommand> values = null; switch (hotKey) { case ISequenceUnit k: values = _trie.Get(new List <ICombination>(k.ToCombination())); break; case ISequence s: values = _trie.Get(s.ToList()); break; default: throw new Exception("not supported!"); } return(values.Any()); }
public ISequence Then(IHotkey hotkey) { this.AddRange(hotkey.ToSequence()); return(this); }
/// <inheritdoc /> public MouseHookHotkey([NotNull] IHotkey hotkey) : base(hotkey) { }
/// <summary> /// Add a hotkey to the list but do not register it /// </summary> /// <param name="hotkey">The hotkey to add</param> private void Add(IHotkey hotkey) { _hotkeys[hotkey.ID] = hotkey; }
/// <inheritdoc /> public KeyboardHotkey([NotNull] IHotkey hotkey) : base(hotkey) { }
public FakeHotkey([NotNull] IHotkey hotkey) : base(hotkey) { }
public IKeyboardCommandTrigger OnAllUp(IHotkey hotkey, string stateTree = KeyStateTrees.Default) { return(OnEvent(hotkey, KeyEvent.AllUp, stateTree)); }
public static IKeyCommand HardMap(this IHotkey key, Key target, Predicate <IKeyEventArgs> canExecute = null) { return(Keyboard.HardMap(key, new Combination(target), canExecute)); }
public static IKeyCommand MapOnDownUp(this IHotkey key, ISequenceUnit target, Predicate <IKeyEventArgs> canExecute = null) { return(Keyboard.MapOnDownUp(key, target, canExecute)); }
public ISequence Then(IHotkey hotkey) => new Combination(this).Then(hotkey);
/// <summary> /// Updates the active hotkey value. /// </summary> /// <param name="hotkey">The new active hotkey.</param> private void UpdateActiveValue(IHotkey hotkey) { this.ActiveHotkey = hotkey; }